From 5064133f1f59be9539ff6a2ebd830132b2379564 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Sat, 15 Jun 2024 00:02:19 +0200 Subject: jsonrpc: separate the RPC errors from the library implementation errors --- jsonrpc/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'jsonrpc/README.md') diff --git a/jsonrpc/README.md b/jsonrpc/README.md index 8127727..4f016b4 100644 --- a/jsonrpc/README.md +++ b/jsonrpc/README.md @@ -31,7 +31,7 @@ use serde_json::Value; use smol::stream::StreamExt; use karyon_jsonrpc::{ - Error, Server, Client, rpc_impl, rpc_pubsub_impl, message::SubscriptionID, + RPCError, Server, Client, rpc_impl, rpc_pubsub_impl, message::SubscriptionID, Channel }; @@ -39,30 +39,30 @@ struct HelloWorld {} #[rpc_impl] impl HelloWorld { - async fn say_hello(&self, params: Value) -> Result { + async fn say_hello(&self, params: Value) -> Result { let msg: String = serde_json::from_value(params)?; Ok(serde_json::json!(format!("Hello {msg}!"))) } - async fn foo(&self, params: Value) -> Result { + async fn foo(&self, params: Value) -> Result { Ok(serde_json::json!("foo!")) } - async fn bar(&self, params: Value) -> Result { + async fn bar(&self, params: Value) -> Result { Ok(serde_json::json!("bar!")) } } #[rpc_pubsub_impl] impl HelloWorld { - async fn log_subscribe(&self, chan: Arc, method: String, _params: Value) -> Result { + async fn log_subscribe(&self, chan: Arc, method: String, _params: Value) -> Result { let sub = chan.new_subscription(&method).await; let sub_id = sub.id.clone(); smol::spawn(async move { loop { smol::Timer::after(std::time::Duration::from_secs(1)).await; if let Err(err) = sub.notify(serde_json::json!("Hello")).await { - println!("Error send notification {err}"); + println!("Failed to send notification: {err}"); break; } } @@ -72,7 +72,7 @@ impl HelloWorld { Ok(serde_json::json!(sub_id)) } - async fn log_unsubscribe(&self, chan: Arc, method: String, params: Value) -> Result { + async fn log_unsubscribe(&self, chan: Arc, method: String, params: Value) -> Result { let sub_id: SubscriptionID = serde_json::from_value(params)?; chan.remove_subscription(&sub_id).await; Ok(serde_json::json!(true)) -- cgit v1.2.3