From b5750365ca5aa9daa6ba40fd489a262e0281d4cb Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Tue, 6 Dec 2016 11:17:26 -0800 Subject: [PATCH] Change readme example to exhibit deadlock... --- examples/readme.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/readme.rs b/examples/readme.rs index 3613332..cbf206d 100644 --- a/examples/readme.rs +++ b/examples/readme.rs @@ -9,9 +9,11 @@ extern crate futures; #[macro_use] extern crate tarpc; +extern crate tokio_core; +use futures::Future; use tarpc::util::Never; -use tarpc::sync::Connect; +use tarpc::future::Connect; service! { rpc hello(name: String) -> String; @@ -27,7 +29,18 @@ impl SyncService for HelloServer { } fn main() { + let mut core = tokio_core::reactor::Core::new().unwrap(); let addr = HelloServer.listen("localhost:10000").unwrap(); - let client = SyncClient::connect(addr).unwrap(); - println!("{}", client.hello("Mom".to_string()).unwrap()); + let f = FutureClient::connect(&addr) + .map_err(tarpc::Error::from) + .and_then(|client| { + let resp1 = client.hello("Mom".to_string()); + let resp2 = client.hello("Dad".to_string()); + futures::collect(vec![resp1, resp2]) + }).map(|responses| { + for resp in responses { + println!("{}", resp); + } + }); + core.run(f).unwrap(); }