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(); }