diff options
author | hozan23 <hozan23@karyontech.net> | 2024-05-23 00:19:58 +0200 |
---|---|---|
committer | hozan23 <hozan23@karyontech.net> | 2024-05-23 00:19:58 +0200 |
commit | 2d1a8aea0b9330cd2eaad26eb187644adad6bed9 (patch) | |
tree | 6083adaa09ae2f0ef2912f7934cdf0bfafff1654 /jsonrpc/README.md | |
parent | cc1d61c401e52ba3b6cd264c5400fb7ab52522dc (diff) |
jsonrpc: spawn task when handle new request
Diffstat (limited to 'jsonrpc/README.md')
-rw-r--r-- | jsonrpc/README.md | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/jsonrpc/README.md b/jsonrpc/README.md index 091af99..03f5ace 100644 --- a/jsonrpc/README.md +++ b/jsonrpc/README.md @@ -16,7 +16,7 @@ features: ## Example ```rust -use std::sync::Arc; +use std::{sync::Arc, time::Duration}; use serde_json::Value; use smol::stream::StreamExt; @@ -45,8 +45,8 @@ impl HelloWorld { #[rpc_pubsub_impl] impl HelloWorld { - async fn log_subscribe(&self, chan: ArcChannel, _params: Value) -> Result<Value, Error> { - let sub = chan.new_subscription().await; + async fn log_subscribe(&self, chan: ArcChannel, method: String, _params: Value) -> Result<Value, Error> { + let sub = chan.new_subscription(&method).await; let sub_id = sub.id.clone(); smol::spawn(async move { loop { @@ -62,7 +62,7 @@ impl HelloWorld { Ok(serde_json::json!(sub_id)) } - async fn log_unsubscribe(&self, chan: ArcChannel, params: Value) -> Result<Value, Error> { + async fn log_unsubscribe(&self, chan: ArcChannel, method: String, params: Value) -> Result<Value, Error> { let sub_id: SubscriptionID = serde_json::from_value(params)?; chan.remove_subscription(&sub_id).await; Ok(serde_json::json!(true)) @@ -84,7 +84,9 @@ async { .expect("build the server"); // Starts the server - server.start().await.expect("start the server"); + server.start().await; + + smol::Timer::after(Duration::MAX).await; }; // Client |