mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-01-01 09:03:48 +01:00
Shuffle around the sync/future modules
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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};
|
||||
|
||||
26
src/lib.rs
26
src/lib.rs
@@ -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()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user