Add streaming example w/ client disconnect (#782)

This commit is contained in:
Lucio Franco
2021-10-07 17:04:26 -04:00
committed by GitHub
parent 5c1bb90ce8
commit 4604042934
3 changed files with 121 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
pub mod pb {
tonic::include_proto!("grpc.examples.echo");
}
use pb::{echo_client::EchoClient, EchoRequest};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = EchoClient::connect("http://[::1]:50051").await.unwrap();
let stream = client
.server_streaming_echo(EchoRequest {
message: "foo".into(),
})
.await
.unwrap();
println!("Connected...now sleeping for 2 seconds...");
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
// Disconnect
drop(stream);
drop(client);
println!("Disconnected...");
Ok(())
}