Move the static remote to the default reactor core to the crate root.

It didn't really make sense in the framed module, which doesn't care about such things.
This commit is contained in:
Tim Kuehn
2016-09-17 18:31:08 -07:00
parent 14c97b61f9
commit 3eb57d4009
4 changed files with 25 additions and 20 deletions

View File

@@ -62,8 +62,9 @@ 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 futures::{self, Async, Future};
use framed::{REMOTE, Framed};
use framed::Framed;
use serde::{Deserialize, Serialize};
use std::cell::RefCell;
use std::io;

View File

@@ -4,32 +4,16 @@
// This file may not be copied, modified, or distributed except according to those terms.
use serde;
use futures::{self, Async};
use futures::Async;
use bincode::{SizeLimit, serde as bincode};
use byteorder::BigEndian;
use bytes::{BlockBuf, BlockBufCursor, Buf, MutBuf};
use std::{cmp, io, mem, thread};
use std::{cmp, io, mem};
use std::marker::PhantomData;
use std::sync::mpsc;
use util::Never;
use tokio_core::io::{FramedIo, Io};
use tokio_core::reactor::{Core, Remote};
use tokio_proto::{self as proto, pipeline};
lazy_static! {
#[doc(hidden)]
pub static ref REMOTE: Remote = {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let mut lupe = Core::new().unwrap();
tx.send(lupe.handle().remote().clone()).unwrap();
// Run forever
lupe.run(futures::empty::<(), !>()).unwrap();
});
rx.recv().unwrap()
};
}
/// Handles the IO of tarpc messages.
pub struct Framed<I, In, Out> {
inner: proto::Framed<I, Parser<Out>, Serializer<In>>,

View File

@@ -115,3 +115,22 @@ mod server;
mod framed;
/// Provides a few different error types.
mod errors;
use std::sync::mpsc;
use std::thread;
use tokio_core::reactor::{Core, Remote};
lazy_static! {
/// The `Remote` for the default reactor core.
pub static ref REMOTE: Remote = {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let mut lupe = Core::new().unwrap();
tx.send(lupe.handle().remote().clone()).unwrap();
// Run forever
lupe.run(futures::empty::<(), !>()).unwrap();
});
rx.recv().unwrap()
};
}

View File

@@ -3,11 +3,12 @@
// 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;
use bincode::serde::DeserializeError;
use errors::WireError;
use futures::{self, Async, Future};
use futures::stream::Empty;
use framed::{REMOTE, Framed};
use framed::Framed;
use serde::{Deserialize, Serialize};
use std::io;
use std::net::ToSocketAddrs;