mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
Swap Handle/Pinned
* Handle -> Remote * Pinned -> Handle All APIs now take a `&Handle` by default and in general can return an immediate `io::Result` instead of an `IoFuture`. This reflects how most usage will likely be done through handles rather than remotes, and also all previous functionality can be recovered with a `oneshot` plus `Remote::spawn`. Closes #15
This commit is contained in:
+4
-20
@@ -6,11 +6,10 @@
|
||||
use std::io;
|
||||
use std::sync::mpsc::TryRecvError;
|
||||
|
||||
use futures::{Future, Poll, Async};
|
||||
use futures::{Poll, Async};
|
||||
use futures::stream::Stream;
|
||||
use mio::channel;
|
||||
|
||||
use io::IoFuture;
|
||||
use reactor::{Handle, PollEvented};
|
||||
|
||||
/// The transmission half of a channel used for sending messages to a receiver.
|
||||
@@ -35,12 +34,6 @@ pub struct Receiver<T> {
|
||||
rx: PollEvented<channel::Receiver<T>>,
|
||||
}
|
||||
|
||||
/// Future returned by the `channel` function which will resolve to a
|
||||
/// `Receiver<T>`.
|
||||
pub struct ReceiverNew<T> {
|
||||
inner: IoFuture<Receiver<T>>,
|
||||
}
|
||||
|
||||
/// Creates a new in-memory channel used for sending data across `Send +
|
||||
/// 'static` boundaries, frequently threads.
|
||||
///
|
||||
@@ -53,12 +46,12 @@ pub struct ReceiverNew<T> {
|
||||
/// The returned `Sender` can be used to send messages that are processed by
|
||||
/// the returned `Receiver`. The `Sender` can be cloned to send messages
|
||||
/// from multiple sources simultaneously.
|
||||
pub fn channel<T>(handle: &Handle) -> (Sender<T>, ReceiverNew<T>)
|
||||
pub fn channel<T>(handle: &Handle) -> io::Result<(Sender<T>, Receiver<T>)>
|
||||
where T: Send + 'static,
|
||||
{
|
||||
let (tx, rx) = channel::channel();
|
||||
let rx = PollEvented::new(rx, handle).map(|rx| Receiver { rx: rx });
|
||||
(Sender { tx: tx }, ReceiverNew { inner: rx.boxed() })
|
||||
let rx = try!(PollEvented::new(rx, handle));
|
||||
Ok((Sender { tx: tx }, Receiver { rx: rx }))
|
||||
}
|
||||
|
||||
impl<T> Sender<T> {
|
||||
@@ -109,12 +102,3 @@ impl<T> Stream for Receiver<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Future for ReceiverNew<T> {
|
||||
type Item = Receiver<T>;
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Receiver<T>, io::Error> {
|
||||
self.inner.poll()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user