Add future::Connect::connect_remotely.

This commit is contained in:
Tim Kuehn
2016-10-29 10:15:39 -07:00
parent 29b6425fb5
commit aaaaf942d6
2 changed files with 14 additions and 8 deletions

View File

@@ -92,7 +92,12 @@ pub mod future {
/// Connects to a server located at the given address, using a remote to the default
/// reactor.
fn connect(addr: &SocketAddr) -> Self::ConnectFut;
fn connect(addr: &SocketAddr) -> Self::ConnectFut {
Self::connect_remotely(addr, &REMOTE)
}
/// Connects to a server located at the given address, using the given reactor remote.
fn connect_remotely(addr: &SocketAddr, remote: &reactor::Remote) -> Self::ConnectFut;
/// Connects to a server located at the given address, using the given reactor handle.
fn connect_with(addr: &SocketAddr, handle: &'a reactor::Handle) -> Self::ConnectWithFut;
@@ -167,12 +172,10 @@ pub mod future {
type ConnectFut = ConnectFuture<Req, Resp, E>;
type ConnectWithFut = ConnectWithFuture<'a, Req, Resp, E>;
/// Starts an event loop on a thread and registers a new client
/// connected to the given address.
fn connect(addr: &SocketAddr) -> Self::ConnectFut {
fn connect_remotely(addr: &SocketAddr, remote: &reactor::Remote) -> Self::ConnectFut {
let addr = *addr;
let (tx, rx) = futures::oneshot();
REMOTE.spawn(move |handle| {
remote.spawn(move |handle| {
let handle2 = handle.clone();
TcpStream::connect(&addr, handle)
.map(move |tcp| Client::new(tcp, &handle2))

View File

@@ -685,9 +685,12 @@ macro_rules! service {
type ConnectFut = __tarpc_service_ConnectFuture<Self>;
type ConnectWithFut = __tarpc_service_ConnectWithFuture<'a, Self>;
fn connect(__tarpc_service_addr: &::std::net::SocketAddr) -> Self::ConnectFut {
let client = <__tarpc_service_Client as $crate::future::Connect>::connect(
__tarpc_service_addr);
fn connect_remotely(__tarpc_service_addr: &::std::net::SocketAddr,
__tarpc_service_remote: &$crate::tokio_core::reactor::Remote)
-> Self::ConnectFut
{
let client = <__tarpc_service_Client as $crate::future::Connect>::connect_remotely(
__tarpc_service_addr, __tarpc_service_remote);
__tarpc_service_ConnectFuture {
inner: $crate::futures::Future::map(client, FutureClient)