aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/examples/client.rs
diff options
context:
space:
mode:
authorhozan23 <hozan23@karyontech.net>2024-06-14 22:49:53 +0200
committerhozan23 <hozan23@karyontech.net>2024-06-14 22:49:53 +0200
commit3429caa87699d986f799a11f6e0f4526e723b655 (patch)
treee548c356fca4eb76742e29d4bab05007468ed14b /jsonrpc/examples/client.rs
parent0c0699c0460c1b149915729223eec701bde481df (diff)
jsonrpc: client use unbounded channels as buffer for sending requests & clean up examples
Diffstat (limited to 'jsonrpc/examples/client.rs')
-rw-r--r--jsonrpc/examples/client.rs45
1 files changed, 26 insertions, 19 deletions
diff --git a/jsonrpc/examples/client.rs b/jsonrpc/examples/client.rs
index 662aacb..0f87ecb 100644
--- a/jsonrpc/examples/client.rs
+++ b/jsonrpc/examples/client.rs
@@ -1,5 +1,6 @@
use std::time::Duration;
+use log::info;
use serde::{Deserialize, Serialize};
use smol::Timer;
@@ -21,29 +22,35 @@ fn main() {
.expect("Create client builder")
.build()
.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();
+ .expect("Create rpc client");
let params = Req { x: 10, y: 7 };
- let result: u32 = client.call("Calc.add", params).await.unwrap();
- println!("result {result}");
+ let result: u32 = client
+ .call("Calc.add", params)
+ .await
+ .expect("Call Calc.add method");
+ info!("Add result: {result}");
let params = Req { x: 10, y: 7 };
- let result: u32 = client.call("Calc.sub", params).await.unwrap();
- println!("result {result}");
-
- let result: String = client.call("Calc.version", ()).await.unwrap();
- println!("result {result}");
+ let result: u32 = client
+ .call("Calc.sub", params)
+ .await
+ .expect("Call Calc.sub method");
+ info!("Sub result: {result}");
- Timer::after(Duration::from_secs(10)).await;
+ let result: String = client
+ .call("Calc.version", ())
+ .await
+ .expect("Call Calc.version method");
+ info!("Version result: {result}");
+
+ loop {
+ Timer::after(Duration::from_millis(100)).await;
+ let result: Pong = client
+ .call("Calc.ping", ())
+ .await
+ .expect("Call Calc.ping method");
+ info!("Ping result: {:?}", result);
+ }
});
}