aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/examples
diff options
context:
space:
mode:
authorhozan23 <hozan23@karyontech.net>2024-05-28 00:19:10 +0200
committerhozan23 <hozan23@karyontech.net>2024-05-28 00:19:10 +0200
commit8afb4d30750840f66d9f97c2c54a893d3934c45e (patch)
treeca3edd785513bcb5b9bcb3fb3847db34bfdebc71 /jsonrpc/examples
parentd1c816660c0583db33d160e2ef3e980bef0d5a85 (diff)
jsonrpc: enable concurrent requests in `Client`
Diffstat (limited to 'jsonrpc/examples')
-rw-r--r--jsonrpc/examples/client.rs18
1 files changed, 15 insertions, 3 deletions
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;
});
}