mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-01-03 09:58:21 +01:00
Fully commit to futures in hello world.
This commit is contained in:
20
README.md
20
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();
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user