aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/examples
diff options
context:
space:
mode:
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;
});
}