From 8afb4d30750840f66d9f97c2c54a893d3934c45e Mon Sep 17 00:00:00 2001 From: hozan23 Date: Tue, 28 May 2024 00:19:10 +0200 Subject: jsonrpc: enable concurrent requests in `Client` --- jsonrpc/examples/client.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'jsonrpc/examples') diff --git a/jsonrpc/examples/client.rs b/jsonrpc/examples/client.rs index 3289772..662aacb 100644 --- a/jsonrpc/examples/client.rs +++ b/jsonrpc/examples/client.rs @@ -1,4 +1,7 @@ +use std::time::Duration; + use serde::{Deserialize, Serialize}; +use smol::Timer; use karyon_jsonrpc::Client; @@ -20,6 +23,16 @@ fn main() { .await .unwrap(); + let clientc = client.clone(); + smol::spawn(async move { + loop { + Timer::after(Duration::from_millis(500)).await; + let result: Pong = clientc.call("Calc.ping", ()).await.unwrap(); + println!("ping msg result: {:?}", result); + } + }) + .detach(); + let params = Req { x: 10, y: 7 }; let result: u32 = client.call("Calc.add", params).await.unwrap(); println!("result {result}"); @@ -28,10 +41,9 @@ fn main() { let result: u32 = client.call("Calc.sub", params).await.unwrap(); println!("result {result}"); - let result: Pong = client.call("Calc.ping", ()).await.unwrap(); - println!("result {:?}", result); - let result: String = client.call("Calc.version", ()).await.unwrap(); println!("result {result}"); + + Timer::after(Duration::from_secs(10)).await; }); } -- cgit v1.2.3