mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-01-04 18:43:54 +01:00
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:
@@ -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;
|
||||
|
||||
@@ -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>>,
|
||||
|
||||
19
src/lib.rs
19
src/lib.rs
@@ -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()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user