Shuffle around the sync/future modules

This commit is contained in:
Tim Kuehn
2016-12-26 16:02:44 -05:00
parent 18cbbe5b15
commit 5dbfa99d0b
5 changed files with 24 additions and 15 deletions

View File

@@ -33,7 +33,7 @@ struct HelloServer;
impl HelloServer {
fn listen(addr: SocketAddr) -> impl Future<Item=SocketAddr, Error=io::Error> {
let (tx, rx) = futures::oneshot();
tarpc::REMOTE.spawn(move |handle| {
tarpc::future::REMOTE.spawn(move |handle| {
Ok(tx.complete(tarpc::listen_with(addr, move || Ok(HelloServer), handle.clone())))
});
rx.map_err(|e| panic!(e)).and_then(|result| result)
@@ -57,7 +57,7 @@ pub struct FutureClient(tarpc::Client<String, String, Never>);
impl FutureClient {
fn connect(addr: &SocketAddr) -> impl Future<Item = FutureClient, Error = io::Error> {
tarpc::Client::connect_remotely(addr, &tarpc::REMOTE).map(FutureClient)
tarpc::Client::connect_remotely(addr, &tarpc::future::REMOTE).map(FutureClient)
}
pub fn hello(&mut self, name: String)

View File

@@ -94,7 +94,7 @@ impl<Req, Resp, E> fmt::Debug for Client<Req, Resp, E>
/// Exposes a trait for connecting asynchronously to servers.
pub mod future {
use REMOTE;
use future::REMOTE;
use futures::{self, Async, Future};
use protocol::Proto;
use serde::{Deserialize, Serialize};

View File

@@ -86,8 +86,6 @@ pub extern crate tokio_proto;
#[doc(hidden)]
pub extern crate tokio_service;
pub use client::{sync, future};
#[doc(hidden)]
pub use client::Client;
#[doc(hidden)]
@@ -115,11 +113,21 @@ mod protocol;
/// Provides a few different error types.
mod errors;
use tokio_core::reactor::Remote;
lazy_static! {
/// The `Remote` for the default reactor core.
pub static ref REMOTE: Remote = {
util::spawn_core()
};
/// Utility specific to synchronous implementation.
pub mod sync {
pub use client::sync::*;
}
/// Utility specific to futures implementation.
pub mod future {
pub use client::future::*;
use tokio_core::reactor::Remote;
use util;
lazy_static! {
/// The `Remote` for the default reactor core.
pub static ref REMOTE: Remote = {
util::spawn_core()
};
}
}

View File

@@ -396,7 +396,7 @@ macro_rules! service {
fn listen(self, addr: ::std::net::SocketAddr) -> $crate::ListenFuture
{
let (tx, rx) = $crate::futures::oneshot();
$crate::REMOTE.spawn(move |handle|
$crate::future::REMOTE.spawn(move |handle|
Ok(tx.complete(Self::listen_with(self,
addr,
handle.clone()))));
@@ -542,7 +542,7 @@ macro_rules! service {
{
let addr = $crate::util::FirstSocketAddr::try_first_socket_addr(&addr)?;
let (tx, rx) = $crate::futures::oneshot();
$crate::REMOTE.spawn(move |handle| Ok(tx.complete(Self::listen_with(self, addr, handle.clone()))));
$crate::future::REMOTE.spawn(move |handle| Ok(tx.complete(Self::listen_with(self, addr, handle.clone()))));
$crate::futures::Future::wait($crate::ListenFuture::from_oneshot(rx))
}

View File

@@ -3,9 +3,10 @@
// 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.
use {REMOTE, net2};
use net2;
use bincode::serde::DeserializeError;
use errors::WireError;
use future::REMOTE;
use protocol::Proto;
use futures::{self, Async, Future, Stream};
use serde::{Deserialize, Serialize};