aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/examples/pubsub_server.rs
diff options
context:
space:
mode:
authorhozan23 <hozan23@karyontech.net>2024-06-15 00:02:19 +0200
committerhozan23 <hozan23@karyontech.net>2024-06-15 00:02:19 +0200
commit5064133f1f59be9539ff6a2ebd830132b2379564 (patch)
tree3722421bea0b3dd21137f9abc98e3e6c950d76d8 /jsonrpc/examples/pubsub_server.rs
parent3429caa87699d986f799a11f6e0f4526e723b655 (diff)
jsonrpc: separate the RPC errors from the library implementation errors
Diffstat (limited to 'jsonrpc/examples/pubsub_server.rs')
-rw-r--r--jsonrpc/examples/pubsub_server.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/jsonrpc/examples/pubsub_server.rs b/jsonrpc/examples/pubsub_server.rs
index 40ea756..d1623c1 100644
--- a/jsonrpc/examples/pubsub_server.rs
+++ b/jsonrpc/examples/pubsub_server.rs
@@ -5,7 +5,9 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use karyon_core::async_util::sleep;
-use karyon_jsonrpc::{message::SubscriptionID, rpc_impl, rpc_pubsub_impl, Channel, Error, Server};
+use karyon_jsonrpc::{
+ message::SubscriptionID, rpc_impl, rpc_pubsub_impl, Channel, RPCError, Server,
+};
struct Calc {}
@@ -20,7 +22,7 @@ struct Pong {}
#[rpc_impl]
impl Calc {
- async fn ping(&self, _params: Value) -> Result<Value, Error> {
+ async fn ping(&self, _params: Value) -> Result<Value, RPCError> {
Ok(serde_json::json!(Pong {}))
}
}
@@ -32,14 +34,14 @@ impl Calc {
chan: Arc<Channel>,
method: String,
_params: Value,
- ) -> Result<Value, Error> {
+ ) -> Result<Value, RPCError> {
let sub = chan.new_subscription(&method).await;
let sub_id = sub.id.clone();
smol::spawn(async move {
loop {
sleep(Duration::from_millis(500)).await;
if let Err(err) = sub.notify(serde_json::json!("Hello")).await {
- error!("Error send notification {err}");
+ error!("Send notification {err}");
break;
}
}
@@ -54,7 +56,7 @@ impl Calc {
chan: Arc<Channel>,
_method: String,
params: Value,
- ) -> Result<Value, Error> {
+ ) -> Result<Value, RPCError> {
let sub_id: SubscriptionID = serde_json::from_value(params)?;
chan.remove_subscription(&sub_id).await;
Ok(serde_json::json!(true))