aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/README.md
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/README.md
parent3429caa87699d986f799a11f6e0f4526e723b655 (diff)
jsonrpc: separate the RPC errors from the library implementation errors
Diffstat (limited to 'jsonrpc/README.md')
-rw-r--r--jsonrpc/README.md14
1 files changed, 7 insertions, 7 deletions
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<Value, Error> {
+ async fn say_hello(&self, params: Value) -> Result<Value, RPCError> {
let msg: String = serde_json::from_value(params)?;
Ok(serde_json::json!(format!("Hello {msg}!")))
}
- async fn foo(&self, params: Value) -> Result<Value, Error> {
+ async fn foo(&self, params: Value) -> Result<Value, RPCError> {
Ok(serde_json::json!("foo!"))
}
- async fn bar(&self, params: Value) -> Result<Value, Error> {
+ async fn bar(&self, params: Value) -> Result<Value, RPCError> {
Ok(serde_json::json!("bar!"))
}
}
#[rpc_pubsub_impl]
impl HelloWorld {
- async fn log_subscribe(&self, chan: Arc<Channel>, method: String, _params: Value) -> Result<Value, Error> {
+ async fn log_subscribe(&self, chan: Arc<Channel>, method: String, _params: Value) -> Result<Value, RPCError> {
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<Channel>, method: String, params: Value) -> Result<Value, Error> {
+ async fn log_unsubscribe(&self, chan: Arc<Channel>, method: String, params: Value) -> Result<Value, RPCError> {
let sub_id: SubscriptionID = serde_json::from_value(params)?;
chan.remove_subscription(&sub_id).await;
Ok(serde_json::json!(true))