blob: bbfd9b4ce03521a3f7d59679210b8479443abe84 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
use std::time::Duration;
use log::info;
use serde::{Deserialize, Serialize};
use smol::Timer;
use karyon_jsonrpc::Client;
#[derive(Deserialize, Serialize, Debug)]
struct Pong {}
async fn run_client() {
let client = Client::builder("tcp://127.0.0.1:6000")
.expect("Create client builder")
.build()
.await
.expect("Build a client");
let clientc = client.clone();
smol::spawn(async move {}).detach();
let sub = client
.subscribe("Calc.log_subscribe", ())
.await
.expect("Subscribe to log_subscribe method");
smol::spawn(async move {
loop {
let m = sub.recv().await.expect("Receive new log msg");
info!("Receive new log {m}");
}
})
.detach();
loop {
Timer::after(Duration::from_millis(500)).await;
let _: Pong = clientc
.call("Calc.ping", ())
.await
.expect("Send ping request");
}
}
fn main() {
env_logger::init();
smol::future::block_on(async {
smol::spawn(run_client()).await;
});
}
|