forked from hyperium/tonic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.rs
More file actions
30 lines (23 loc) · 800 Bytes
/
client.rs
File metadata and controls
30 lines (23 loc) · 800 Bytes
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
use hello_world::greeter_client::GreeterClient;
use hello_world::HelloRequest;
use tokio::time::{timeout, Duration};
pub mod hello_world {
tonic::include_proto!("helloworld");
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = GreeterClient::connect("http://[::1]:50051").await?;
let request = tonic::Request::new(HelloRequest {
name: "Tonic".into(),
});
// Cancelling the request by dropping the request future after 1 second
let response = match timeout(Duration::from_secs(1), client.say_hello(request)).await {
Ok(response) => response?,
Err(_) => {
println!("Cancelled request after 1s");
return Ok(());
}
};
println!("RESPONSE={response:?}");
Ok(())
}