Change readme example to exhibit deadlock...

This commit is contained in:
Tim Kuehn
2016-12-06 11:17:26 -08:00
parent f6b1660092
commit b5750365ca

View File

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