diff --git a/README.md b/README.md index e7d6b27..0dfb6a8 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ races! See the tarpc_examples package for more examples. ## Example: Futures -Here's the same service, implemented using `FutureService`. +Here's the same service, implemented using futures. ```rust #![feature(conservative_impl_trait, plugin)] @@ -96,9 +96,12 @@ Here's the same service, implemented using `FutureService`. extern crate futures; #[macro_use] extern crate tarpc; +extern crate tokio_core; +use futures::Future; +use tarpc::future::Connect; use tarpc::util::{FirstSocketAddr, Never}; -use tarpc::sync::Connect; +use tokio_core::reactor; service! { rpc hello(name: String) -> String; @@ -116,10 +119,15 @@ impl FutureService for HelloServer { } fn main() { - let addr = "localhost:10000"; - let _server = HelloServer.listen(addr.first_socket_addr()); - let mut client = SyncClient::connect(addr).unwrap(); - println!("{}", client.hello("Mom".to_string()).unwrap()); + let addr = "localhost:10000".first_socket_addr(); + let mut core = reactor::Core::new().unwrap(); + HelloServer.listen_with(addr, core.handle()).unwrap(); + core.run( + FutureClient::connect(&addr) + .map_err(tarpc::Error::from) + .and_then(|mut client| client.hello("Mom".to_string())) + .map(|resp| println!("{}", resp)) + ).unwrap(); } ``` diff --git a/examples/readme_futures.rs b/examples/readme_futures.rs index b9de630..90022a6 100644 --- a/examples/readme_futures.rs +++ b/examples/readme_futures.rs @@ -9,9 +9,12 @@ extern crate futures; #[macro_use] extern crate tarpc; +extern crate tokio_core; +use futures::Future; +use tarpc::future::Connect; use tarpc::util::{FirstSocketAddr, Never}; -use tarpc::sync::Connect; +use tokio_core::reactor; service! { rpc hello(name: String) -> String; @@ -29,8 +32,13 @@ impl FutureService for HelloServer { } fn main() { - let addr = "localhost:10000"; - let _server = HelloServer.listen(addr.first_socket_addr()); - let mut client = SyncClient::connect(addr).unwrap(); - println!("{}", client.hello("Mom".to_string()).unwrap()); + let addr = "localhost:10000".first_socket_addr(); + let mut core = reactor::Core::new().unwrap(); + HelloServer.listen_with(addr, core.handle()).unwrap(); + core.run( + FutureClient::connect(&addr) + .map_err(tarpc::Error::from) + .and_then(|mut client| client.hello("Mom".to_string())) + .map(|resp| println!("{}", resp)) + ).unwrap(); }