Track latest tokio changes

This commit is contained in:
Tim Kuehn
2016-12-26 00:27:23 -05:00
parent bdd6737914
commit d242bdbb82
16 changed files with 139 additions and 159 deletions

View File

@@ -28,8 +28,8 @@ tokio-core = { git = "https://github.com/tokio-rs/tokio-core" }
net2 = "0.2"
[replace]
"tokio-core:0.1.1" = { git = "https://github.com/tokio-rs/tokio-core" }
"futures:0.1.6" = { git = "https://github.com/alexcrichton/futures-rs" }
"tokio-core:0.1.2" = { git = "https://github.com/tokio-rs/tokio-core" }
"futures:0.1.7" = { git = "https://github.com/alexcrichton/futures-rs" }
[dev-dependencies]
chrono = "0.2"

View File

@@ -62,7 +62,7 @@ service! {
struct HelloServer;
impl SyncService for HelloServer {
fn hello(&self, name: String) -> Result<String, Never> {
fn hello(&mut self, name: String) -> Result<String, Never> {
Ok(format!("Hello, {}!", name))
}
}
@@ -70,7 +70,7 @@ impl SyncService for HelloServer {
fn main() {
let addr = "localhost:10000";
HelloServer.listen(addr).unwrap();
let client = SyncClient::connect(addr).unwrap();
let mut client = SyncClient::connect(addr).unwrap();
println!("{}", client.hello("Mom".to_string()).unwrap());
}
```
@@ -87,7 +87,7 @@ races! See the tarpc_examples package for more examples.
## Example: Futures
Here's the same server, implemented using `FutureService`.
Here's the same service, implemented using `FutureService`.
```rust
#![feature(conservative_impl_trait, plugin)]
@@ -110,7 +110,7 @@ struct HelloServer;
impl FutureService for HelloServer {
type HelloFut = futures::Finished<String, Never>;
fn hello(&self, name: String) -> Self::HelloFut {
fn hello(&mut self, name: String) -> Self::HelloFut {
futures::finished(format!("Hello, {}!", name))
}
}
@@ -118,7 +118,7 @@ impl FutureService for HelloServer {
fn main() {
let addr = "localhost:10000";
let _server = HelloServer.listen(addr.first_socket_addr());
let client = SyncClient::connect(addr).unwrap();
let mut client = SyncClient::connect(addr).unwrap();
println!("{}", client.hello("Mom".to_string()).unwrap());
}
```

View File

@@ -18,11 +18,12 @@ extern crate tokio_core;
extern crate futures_cpupool;
use clap::{Arg, App};
use futures::Future;
use futures::{Future, Stream};
use futures_cpupool::{CpuFuture, CpuPool};
use std::cmp;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::{Duration, Instant, SystemTime};
use std::time::{Duration, Instant};
use tarpc::future::{Connect};
use tarpc::util::{FirstSocketAddr, Never, spawn_core};
use tokio_core::reactor;
@@ -49,7 +50,7 @@ impl Server {
impl FutureService for Server {
type ReadFut = CpuFuture<Vec<u8>, Never>;
fn read(&self, size: u32) -> Self::ReadFut {
fn read(&mut self, size: u32) -> Self::ReadFut {
let request_number = self.request_count.fetch_add(1, Ordering::SeqCst);
debug!("Server received read({}) no. {}", size, request_number);
self.pool
@@ -79,44 +80,48 @@ impl Microseconds for Duration {
}
}
fn run_once(clients: Vec<FutureClient>, concurrency: u32) -> impl Future<Item=(), Error=()> {
#[derive(Default)]
struct Stats {
sum: Duration,
count: u64,
min: Option<Duration>,
max: Option<Duration>,
}
fn run_once(mut clients: Vec<FutureClient>, concurrency: u32) -> impl Future<Item=(), Error=()> + 'static {
let start = Instant::now();
let futs = clients.iter()
.enumerate()
.cycle()
.enumerate()
.take(concurrency as usize)
.map(|(iteration, (client_id, client))| {
let iteration = iteration + 1;
let start = SystemTime::now();
debug!("Client {} reading (iteration {})...", client_id, iteration);
let future = client.read(CHUNK_SIZE).map(move |_| {
let elapsed = start.elapsed().unwrap();
debug!("Client {} received reply (iteration {}).", client_id, iteration);
elapsed
});
future
let num_clients = clients.len();
futures::stream::futures_unordered((0..concurrency as usize)
.map(|iteration| (iteration + 1, iteration % num_clients))
.map(|(iteration, client_idx)| {
let mut client = &mut clients[client_idx];
let start = Instant::now();
debug!("Client {} reading (iteration {})...", client_idx, iteration);
client.read(CHUNK_SIZE)
.map(move |_| (client_idx, iteration, start))
}))
//.collect::<FuturesUnordered<_>>()
.map(|(client_idx, iteration, start)| {
let elapsed = start.elapsed();
debug!("Client {} received reply (iteration {}).", client_idx, iteration);
elapsed
})
.map_err(|e| panic!(e))
.fold(Stats::default(), move |mut stats, elapsed| {
stats.sum += elapsed;
stats.count += 1;
stats.min = Some(cmp::min(stats.min.unwrap_or(elapsed), elapsed));
stats.max = Some(cmp::max(stats.max.unwrap_or(elapsed), elapsed));
Ok(stats)
})
.map(move |stats| {
info!("{} requests => Mean={}µs, Min={}µs, Max={}µs, Total={}µs",
stats.count,
stats.sum.microseconds() as f64 / stats.count as f64,
stats.min.unwrap().microseconds(),
stats.max.unwrap().microseconds(),
start.elapsed().microseconds());
})
// Need an intermediate collection to kick off each future,
// because futures::collect will iterate sequentially.
.collect::<Vec<_>>();
let futs = futures::collect(futs);
futs.map(move |latencies| {
let total_time = start.elapsed();
let sum_latencies = latencies.iter().fold(Duration::new(0, 0), |sum, &dur| sum + dur);
let mean = sum_latencies / latencies.len() as u32;
let min_latency = *latencies.iter().min().unwrap();
let max_latency = *latencies.iter().max().unwrap();
info!("{} requests => Mean={}µs, Min={}µs, Max={}µs, Total={}µs",
latencies.len(),
mean.microseconds(),
min_latency.microseconds(),
max_latency.microseconds(),
total_time.microseconds());
}).map_err(|e| panic!(e))
}
fn main() {

View File

@@ -49,7 +49,7 @@ struct Subscriber {
impl subscriber::FutureService for Subscriber {
type ReceiveFut = futures::Finished<(), Never>;
fn receive(&self, message: String) -> Self::ReceiveFut {
fn receive(&mut self, message: String) -> Self::ReceiveFut {
println!("{} received message: {}", self.id, message);
futures::finished(())
}
@@ -80,11 +80,11 @@ impl Publisher {
impl publisher::FutureService for Publisher {
type BroadcastFut = BoxFuture<(), Never>;
fn broadcast(&self, message: String) -> Self::BroadcastFut {
fn broadcast(&mut self, message: String) -> Self::BroadcastFut {
futures::collect(self.clients
.lock()
.unwrap()
.values()
.values_mut()
// Ignore failing subscribers.
.map(move |client| client.receive(message.clone()).then(|_| Ok(())))
.collect::<Vec<_>>())
@@ -94,7 +94,7 @@ impl publisher::FutureService for Publisher {
type SubscribeFut = BoxFuture<(), Message>;
fn subscribe(&self, id: u32, address: SocketAddr) -> Self::SubscribeFut {
fn subscribe(&mut self, id: u32, address: SocketAddr) -> Self::SubscribeFut {
let clients = self.clients.clone();
subscriber::FutureClient::connect(&address)
.map(move |subscriber| {
@@ -108,7 +108,7 @@ impl publisher::FutureService for Publisher {
type UnsubscribeFut = BoxFuture<(), Never>;
fn unsubscribe(&self, id: u32) -> Self::UnsubscribeFut {
fn unsubscribe(&mut self, id: u32) -> Self::UnsubscribeFut {
println!("Unsubscribing {}", id);
self.clients.lock().unwrap().remove(&id).unwrap();
futures::finished(()).boxed()
@@ -122,7 +122,7 @@ fn main() {
.wait()
.unwrap();
let publisher_client = publisher::SyncClient::connect(publisher_addr).unwrap();
let mut publisher_client = publisher::SyncClient::connect(publisher_addr).unwrap();
let subscriber1 = Subscriber::new(0);
publisher_client.subscribe(0, subscriber1).unwrap();

View File

@@ -1,55 +0,0 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
// This file may not be copied, modified, or distributed except according to those terms.
#![feature(conservative_impl_trait, plugin)]
#![plugin(tarpc_plugins)]
extern crate env_logger;
extern crate futures;
#[macro_use]
extern crate log;
#[macro_use]
extern crate tarpc;
extern crate tokio_core;
use futures::Future;
use tarpc::util::Never;
use tarpc::future::Connect;
service! {
rpc hello(name: String) -> String;
}
#[derive(Clone)]
struct HelloServer;
impl SyncService for HelloServer {
fn hello(&self, name: String) -> Result<String, Never> {
info!("Got request: {}", name);
Ok(format!("Hello, {}!", name))
}
}
fn main() {
let _ = env_logger::init();
let mut core = tokio_core::reactor::Core::new().unwrap();
let addr = HelloServer.listen("localhost:10000").unwrap();
let f = FutureClient::connect(&addr)
.map_err(tarpc::Error::from)
.and_then(|client| {
let resp1 = client.hello("Mom".to_string());
info!("Sent first request.");
/*
let resp2 = client.hello("Dad".to_string());
info!("Sent second request.");
*/
futures::collect(vec![resp1, /*resp2*/])
}).map(|responses| {
for resp in responses {
println!("{}", resp);
}
});
core.run(f).unwrap();
}

View File

@@ -39,7 +39,7 @@ impl Error for NoNameGiven {
struct HelloServer;
impl SyncService for HelloServer {
fn hello(&self, name: String) -> Result<String, NoNameGiven> {
fn hello(&mut self, name: String) -> Result<String, NoNameGiven> {
if name == "" {
Err(NoNameGiven)
} else {
@@ -50,7 +50,7 @@ impl SyncService for HelloServer {
fn main() {
let addr = HelloServer.listen("localhost:10000").unwrap();
let client = SyncClient::connect(addr).unwrap();
let mut client = SyncClient::connect(addr).unwrap();
println!("{}", client.hello("Mom".to_string()).unwrap());
println!("{}", client.hello("".to_string()).unwrap_err());
}

View File

@@ -46,7 +46,7 @@ impl Service for HelloServer {
type Error = io::Error;
type Future = Box<Future<Item = tarpc::Response<String, Never>, Error = io::Error>>;
fn call(&self, request: Self::Request) -> Self::Future {
fn call(&mut self, request: Self::Request) -> Self::Future {
Ok(Ok(format!("Hello, {}!", request.unwrap()))).into_future().boxed()
}
}
@@ -60,7 +60,7 @@ impl FutureClient {
tarpc::Client::connect_remotely(addr, &tarpc::REMOTE).map(FutureClient)
}
pub fn hello(&self, name: String)
pub fn hello(&mut self, name: String)
-> impl Future<Item = String, Error = tarpc::Error<Never>> + 'static
{
self.0.call(name).then(|msg| msg.unwrap())
@@ -73,7 +73,7 @@ fn main() {
let addr = HelloServer::listen("localhost:10000".first_socket_addr()).wait().unwrap();
let f = FutureClient::connect(&addr)
.map_err(tarpc::Error::from)
.and_then(|client| {
.and_then(|mut client| {
let resp1 = client.hello("Mom".to_string());
info!("Sent first request.");

View File

@@ -10,7 +10,6 @@ extern crate futures;
#[macro_use]
extern crate tarpc;
use futures::Future;
use tarpc::util::{FirstSocketAddr, Never};
use tarpc::sync::Connect;
@@ -24,13 +23,14 @@ struct HelloServer;
impl FutureService for HelloServer {
type HelloFut = futures::Finished<String, Never>;
fn hello(&self, name: String) -> Self::HelloFut {
fn hello(&mut self, name: String) -> Self::HelloFut {
futures::finished(format!("Hello, {}!", name))
}
}
fn main() {
let addr = HelloServer.listen("localhost:10000".first_socket_addr()).wait().unwrap();
let client = SyncClient::connect(addr).unwrap();
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());
}

35
examples/readme_sync.rs Normal file
View File

@@ -0,0 +1,35 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
// This file may not be copied, modified, or distributed except according to those terms.
// required by `FutureClient` (not used in this example)
#![feature(conservative_impl_trait, plugin)]
#![plugin(tarpc_plugins)]
extern crate futures;
#[macro_use]
extern crate tarpc;
use tarpc::util::Never;
use tarpc::sync::Connect;
service! {
rpc hello(name: String) -> String;
}
#[derive(Clone)]
struct HelloServer;
impl SyncService for HelloServer {
fn hello(&mut self, name: String) -> Result<String, Never> {
Ok(format!("Hello, {}!", name))
}
}
fn main() {
let addr = "localhost:10000";
HelloServer.listen(addr).unwrap();
let mut client = SyncClient::connect(addr).unwrap();
println!("{}", client.hello("Mom".to_string()).unwrap());
}

View File

@@ -41,7 +41,7 @@ struct AddServer;
impl AddFutureService for AddServer {
type AddFut = futures::Finished<i32, Never>;
fn add(&self, x: i32, y: i32) -> Self::AddFut {
fn add(&mut self, x: i32, y: i32) -> Self::AddFut {
futures::finished(x + y)
}
}
@@ -54,7 +54,7 @@ struct DoubleServer {
impl DoubleServer {
fn new(client: add::FutureClient) -> Self {
DoubleServer {
client: Arc::new(Mutex::new(client))
client: Arc::new(Mutex::new(client)),
}
}
}
@@ -62,7 +62,7 @@ impl DoubleServer {
impl DoubleFutureService for DoubleServer {
type DoubleFut = BoxFuture<i32, Message>;
fn double(&self, x: i32) -> Self::DoubleFut {
fn double(&mut self, x: i32) -> Self::DoubleFut {
self.client
.lock()
.unwrap()
@@ -80,7 +80,7 @@ fn main() {
let double = DoubleServer::new(add_client);
let double_addr = double.listen("localhost:0".first_socket_addr()).wait().unwrap();
let double_client = double::SyncClient::connect(&double_addr).unwrap();
let mut double_client = double::SyncClient::connect(&double_addr).unwrap();
for i in 0..5 {
println!("{:?}", double_client.double(i).unwrap());
}

View File

@@ -44,7 +44,7 @@ struct Server;
impl FutureService for Server {
type ReadFut = futures::Finished<Arc<Vec<u8>>, Never>;
fn read(&self) -> Self::ReadFut {
fn read(&mut self) -> Self::ReadFut {
futures::finished(BUF.clone())
}
}
@@ -53,7 +53,7 @@ const CHUNK_SIZE: u32 = 1 << 19;
fn bench_tarpc(target: u64) {
let addr = Server.listen("localhost:0".first_socket_addr()).wait().unwrap();
let client = SyncClient::connect(&addr).unwrap();
let mut client = SyncClient::connect(&addr).unwrap();
let start = time::Instant::now();
let mut nread = 0;
while nread < target {

View File

@@ -31,7 +31,7 @@ struct Bar;
impl bar::FutureService for Bar {
type BarFut = futures::Finished<i32, Never>;
fn bar(&self, i: i32) -> Self::BarFut {
fn bar(&mut self, i: i32) -> Self::BarFut {
futures::finished(i)
}
}
@@ -47,7 +47,7 @@ struct Baz;
impl baz::FutureService for Baz {
type BazFut = futures::Finished<String, Never>;
fn baz(&self, s: String) -> Self::BazFut {
fn baz(&mut self, s: String) -> Self::BazFut {
futures::finished(format!("Hello, {}!", s))
}
}
@@ -61,8 +61,8 @@ fn main() {
let bar_addr = Bar.listen("localhost:0".first_socket_addr()).wait().unwrap();
let baz_addr = Baz.listen("localhost:0".first_socket_addr()).wait().unwrap();
let bar_client = bar::SyncClient::connect(&bar_addr).unwrap();
let baz_client = baz::SyncClient::connect(&baz_addr).unwrap();
let mut bar_client = bar::SyncClient::connect(&bar_addr).unwrap();
let mut baz_client = baz::SyncClient::connect(&baz_addr).unwrap();
info!("Result: {:?}", bar_client.bar(17));

View File

@@ -42,7 +42,7 @@ impl<Req, Resp, E> Service for Client<Req, Resp, E>
type Error = io::Error;
type Future = ResponseFuture<Req, Resp, E>;
fn call(&self, request: Self::Request) -> Self::Future {
fn call(&mut self, request: Self::Request) -> Self::Future {
self.inner.call(request).map(Self::map_err)
}
}

View File

@@ -10,13 +10,9 @@ use std::io::{self, Cursor};
use std::marker::PhantomData;
use std::mem;
use tokio_core::io::{EasyBuf, Framed, Io};
use tokio_proto::streaming::multiplex::{self, RequestId};
use tokio_proto::streaming::multiplex::RequestId;
use tokio_proto::multiplex::{ClientProto, ServerProto};
use util::{Debugger, Never};
/// The type of message sent and received by the transport.
pub type Frame<T> = multiplex::Frame<T, Never, io::Error>;
use util::Debugger;
// `T` is the type that `Codec` parses.
pub struct Codec<Req, Resp> {
@@ -53,8 +49,7 @@ impl<Req, Resp> tokio_core::io::Codec for Codec<Req, Resp>
bincode::serialize_into(buf,
&message,
SizeLimit::Infinite)
// TODO(tikue): handle err
.expect("In bincode::serialize_into");
.map_err(|serialize_err| io::Error::new(io::ErrorKind::Other, serialize_err))?;
trace!("Encoded buffer: {:?}", buf);
Ok(())
}

View File

@@ -45,7 +45,7 @@
//! struct HelloServer;
//!
//! impl SyncService for HelloServer {
//! fn hello(&self, name: String) -> Result<String, Never> {
//! fn hello(&mut self, name: String) -> Result<String, Never> {
//! Ok(format!("Hello, {}!", name))
//! }
//! }
@@ -53,7 +53,7 @@
//! fn main() {
//! let addr = "localhost:10000";
//! let _server = HelloServer.listen(addr);
//! let client = SyncClient::connect(addr).unwrap();
//! let mut client = SyncClient::connect(addr).unwrap();
//! println!("{}", client.hello("Mom".to_string()).unwrap());
//! }
//! ```

View File

@@ -386,7 +386,7 @@ macro_rules! service {
}
$(#[$attr])*
fn $fn_name(&self, $($arg:$in_),*) -> ty_snake_to_camel!(Self::$fn_name);
fn $fn_name(&mut self, $($arg:$in_),*) -> ty_snake_to_camel!(Self::$fn_name);
)*
}
@@ -477,7 +477,7 @@ macro_rules! service {
type Error = ::std::io::Error;
type Future = __tarpc_service_FutureReply<__tarpc_service_S>;
fn call(&self, __tarpc_service_request: Self::Request) -> Self::Future {
fn call(&mut self, __tarpc_service_request: Self::Request) -> Self::Future {
let __tarpc_service_request = match __tarpc_service_request {
Ok(__tarpc_service_request) => __tarpc_service_request,
Err(__tarpc_service_deserialize_err) => {
@@ -510,7 +510,7 @@ macro_rules! service {
}
return __tarpc_service_FutureReply::$fn_name(
$crate::futures::Future::then(
FutureService::$fn_name(&self.0, $($arg),*),
FutureService::$fn_name(&mut self.0, $($arg),*),
__tarpc_service_wrap));
}
)*
@@ -530,7 +530,7 @@ macro_rules! service {
{
$(
$(#[$attr])*
fn $fn_name(&self, $($arg:$in_),*) -> ::std::result::Result<$out, $error>;
fn $fn_name(&mut self, $($arg:$in_),*) -> ::std::result::Result<$out, $error>;
)*
}
@@ -579,19 +579,19 @@ macro_rules! service {
$crate::futures::Done<$out, $error>>,
fn($crate::futures::Canceled) -> $error>>;
}
fn $fn_name(&self, $($arg:$in_),*) -> ty_snake_to_camel!(Self::$fn_name) {
fn $fn_name(&mut self, $($arg:$in_),*) -> ty_snake_to_camel!(Self::$fn_name) {
fn unimplemented(_: $crate::futures::Canceled) -> $error {
// TODO(tikue): what do do if SyncService panics?
unimplemented!()
}
let (__tarpc_service_complete, __tarpc_service_promise) =
$crate::futures::oneshot();
let __tarpc_service_service = self.clone();
let mut __tarpc_service_service = self.clone();
const UNIMPLEMENTED: fn($crate::futures::Canceled) -> $error =
unimplemented;
::std::thread::spawn(move || {
let __tarpc_service_reply = SyncService::$fn_name(
&__tarpc_service_service.service, $($arg),*);
&mut __tarpc_service_service.service, $($arg),*);
__tarpc_service_complete.complete(
$crate::futures::IntoFuture::into_future(
__tarpc_service_reply));
@@ -629,7 +629,7 @@ macro_rules! service {
$(
#[allow(unused)]
$(#[$attr])*
pub fn $fn_name(&self, $($arg: $in_),*)
pub fn $fn_name(&mut self, $($arg: $in_),*)
-> ::std::result::Result<$out, $crate::Error<$error>>
{
let rpc = (self.0).$fn_name($($arg),*);
@@ -719,13 +719,13 @@ macro_rules! service {
$(
#[allow(unused)]
$(#[$attr])*
pub fn $fn_name(&self, $($arg: $in_),*)
pub fn $fn_name(&mut self, $($arg: $in_),*)
-> impl $crate::futures::Future<Item=$out, Error=$crate::Error<$error>>
+ 'static
{
let __tarpc_service_req = __tarpc_service_Request::$fn_name(($($arg,)*));
let __tarpc_service_fut =
$crate::tokio_service::Service::call(&self.0, __tarpc_service_req);
$crate::tokio_service::Service::call(&mut self.0, __tarpc_service_req);
$crate::futures::Future::then(__tarpc_service_fut,
move |__tarpc_service_msg| {
match __tarpc_service_msg? {
@@ -822,10 +822,10 @@ mod functional_test {
struct Server;
impl SyncService for Server {
fn add(&self, x: i32, y: i32) -> Result<i32, Never> {
fn add(&mut self, x: i32, y: i32) -> Result<i32, Never> {
Ok(x + y)
}
fn hey(&self, name: String) -> Result<String, Never> {
fn hey(&mut self, name: String) -> Result<String, Never> {
Ok(format!("Hey, {}.", name))
}
}
@@ -834,7 +834,7 @@ mod functional_test {
fn simple() {
let _ = env_logger::init();
let addr = Server.listen("localhost:0".first_socket_addr()).unwrap();
let client = SyncClient::connect(addr).unwrap();
let mut client = SyncClient::connect(addr).unwrap();
assert_eq!(3, client.add(1, 2).unwrap());
assert_eq!("Hey, Tim.", client.hey("Tim".to_string()).unwrap());
}
@@ -843,7 +843,7 @@ mod functional_test {
fn other_service() {
let _ = env_logger::init();
let addr = Server.listen("localhost:0".first_socket_addr()).unwrap();
let client = super::other_service::SyncClient::connect(addr).expect("Could not connect!");
let mut client = super::other_service::SyncClient::connect(addr).expect("Could not connect!");
match client.foo().err().unwrap() {
::Error::ServerDeserialize(_) => {} // good
bad => panic!("Expected Error::ServerDeserialize but got {}", bad),
@@ -865,13 +865,13 @@ mod functional_test {
impl FutureService for Server {
type AddFut = Finished<i32, Never>;
fn add(&self, x: i32, y: i32) -> Self::AddFut {
fn add(&mut self, x: i32, y: i32) -> Self::AddFut {
finished(x + y)
}
type HeyFut = Finished<String, Never>;
fn hey(&self, name: String) -> Self::HeyFut {
fn hey(&mut self, name: String) -> Self::HeyFut {
finished(format!("Hey, {}.", name))
}
}
@@ -880,7 +880,7 @@ mod functional_test {
fn simple() {
let _ = env_logger::init();
let addr = Server.listen("localhost:0".first_socket_addr()).wait().unwrap();
let client = FutureClient::connect(&addr).wait().unwrap();
let mut client = FutureClient::connect(&addr).wait().unwrap();
assert_eq!(3, client.add(1, 2).wait().unwrap());
assert_eq!("Hey, Tim.", client.hey("Tim".to_string()).wait().unwrap());
}
@@ -889,7 +889,7 @@ mod functional_test {
fn concurrent() {
let _ = env_logger::init();
let addr = Server.listen("localhost:0".first_socket_addr()).wait().unwrap();
let client = FutureClient::connect(&addr).wait().unwrap();
let mut client = FutureClient::connect(&addr).wait().unwrap();
let req1 = client.add(1, 2);
let req2 = client.add(3, 4);
let req3 = client.hey("Tim".to_string());
@@ -902,7 +902,7 @@ mod functional_test {
fn other_service() {
let _ = env_logger::init();
let addr = Server.listen("localhost:0".first_socket_addr()).wait().unwrap();
let client =
let mut client =
super::other_service::FutureClient::connect(&addr).wait().unwrap();
match client.foo().wait().err().unwrap() {
::Error::ServerDeserialize(_) => {} // good
@@ -923,7 +923,7 @@ mod functional_test {
impl error_service::FutureService for ErrorServer {
type BarFut = ::futures::Failed<u32, ::util::Message>;
fn bar(&self) -> Self::BarFut {
fn bar(&mut self) -> Self::BarFut {
info!("Called bar");
failed("lol jk".into())
}
@@ -938,7 +938,7 @@ mod functional_test {
let _ = env_logger::init();
let addr = ErrorServer.listen("localhost:0".first_socket_addr()).wait().unwrap();
let client = FutureClient::connect(&addr).wait().unwrap();
let mut client = FutureClient::connect(&addr).wait().unwrap();
client.bar()
.then(move |result| {
match result.err().unwrap() {
@@ -952,7 +952,7 @@ mod functional_test {
.wait()
.unwrap();
let client = SyncClient::connect(&addr).unwrap();
let mut client = SyncClient::connect(&addr).unwrap();
match client.bar().err().unwrap() {
::Error::App(e) => {
assert_eq!(e.description(), "lol jk");