Revert "refactor(lib): convert to futures 0.2.0-beta (#1470)"
This reverts commit a12f7beed9.
Much sadness 😢.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use futures::{Async, Never, Poll, Stream};
|
||||
use futures::channel::{mpsc, oneshot};
|
||||
use futures::task;
|
||||
use futures::{Async, Poll, Stream};
|
||||
use futures::sync::{mpsc, oneshot};
|
||||
use want;
|
||||
|
||||
use common::Never;
|
||||
|
||||
//pub type Callback<T, U> = oneshot::Sender<Result<U, (::Error, Option<T>)>>;
|
||||
pub type RetryPromise<T, U> = oneshot::Receiver<Result<U, (::Error, Option<T>)>>;
|
||||
pub type Promise<T> = oneshot::Receiver<Result<T, ::Error>>;
|
||||
@@ -32,15 +33,15 @@ pub struct Sender<T, U> {
|
||||
}
|
||||
|
||||
impl<T, U> Sender<T, U> {
|
||||
pub fn poll_ready(&mut self, cx: &mut task::Context) -> Poll<(), ::Error> {
|
||||
match self.inner.poll_ready(cx) {
|
||||
pub fn poll_ready(&mut self) -> Poll<(), ::Error> {
|
||||
match self.inner.poll_ready() {
|
||||
Ok(Async::Ready(())) => {
|
||||
// there's room in the queue, but does the Connection
|
||||
// want a message yet?
|
||||
self.giver.poll_want(cx)
|
||||
self.giver.poll_want()
|
||||
.map_err(|_| ::Error::Closed)
|
||||
},
|
||||
Ok(Async::Pending) => Ok(Async::Pending),
|
||||
Ok(Async::NotReady) => Ok(Async::NotReady),
|
||||
Err(_) => Err(::Error::Closed),
|
||||
}
|
||||
}
|
||||
@@ -78,15 +79,16 @@ impl<T, U> Stream for Receiver<T, U> {
|
||||
type Item = (T, Callback<T, U>);
|
||||
type Error = Never;
|
||||
|
||||
fn poll_next(&mut self, cx: &mut task::Context) -> Poll<Option<Self::Item>, Self::Error> {
|
||||
match self.inner.poll_next(cx)? {
|
||||
Async::Ready(item) => Ok(Async::Ready(item.map(|mut env| {
|
||||
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
||||
match self.inner.poll() {
|
||||
Ok(Async::Ready(item)) => Ok(Async::Ready(item.map(|mut env| {
|
||||
env.0.take().expect("envelope not dropped")
|
||||
}))),
|
||||
Async::Pending => {
|
||||
Ok(Async::NotReady) => {
|
||||
self.taker.want();
|
||||
Ok(Async::Pending)
|
||||
Ok(Async::NotReady)
|
||||
}
|
||||
Err(()) => unreachable!("mpsc never errors"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,11 +111,11 @@ impl<T, U> Drop for Receiver<T, U> {
|
||||
// This poll() is safe to call in `Drop`, because we've
|
||||
// called, `close`, which promises that no new messages
|
||||
// will arrive, and thus, once we reach the end, we won't
|
||||
// see a `Pending` (and try to park), but a Ready(None).
|
||||
// see a `NotReady` (and try to park), but a Ready(None).
|
||||
//
|
||||
// All other variants:
|
||||
// - Ready(None): the end. we want to stop looping
|
||||
// - Pending: unreachable
|
||||
// - NotReady: unreachable
|
||||
// - Err: unreachable
|
||||
while let Ok(Async::Ready(Some((val, cb)))) = self.inner.poll() {
|
||||
let _ = cb.send(Err((::Error::new_canceled(None::<::Error>), Some(val))));
|
||||
@@ -139,10 +141,10 @@ pub enum Callback<T, U> {
|
||||
}
|
||||
|
||||
impl<T, U> Callback<T, U> {
|
||||
pub fn poll_cancel(&mut self, cx: &mut task::Context) -> Poll<(), Never> {
|
||||
pub fn poll_cancel(&mut self) -> Poll<(), ()> {
|
||||
match *self {
|
||||
Callback::Retry(ref mut tx) => tx.poll_cancel(cx),
|
||||
Callback::NoRetry(ref mut tx) => tx.poll_cancel(cx),
|
||||
Callback::Retry(ref mut tx) => tx.poll_cancel(),
|
||||
Callback::NoRetry(ref mut tx) => tx.poll_cancel(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,8 +166,7 @@ mod tests {
|
||||
#[cfg(feature = "nightly")]
|
||||
extern crate test;
|
||||
|
||||
use futures::{future, FutureExt};
|
||||
use futures::executor::block_on;
|
||||
use futures::{future, Future};
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
use futures::{Stream};
|
||||
@@ -174,7 +175,7 @@ mod tests {
|
||||
fn drop_receiver_sends_cancel_errors() {
|
||||
let _ = pretty_env_logger::try_init();
|
||||
|
||||
block_on(future::lazy(|_| {
|
||||
future::lazy(|| {
|
||||
#[derive(Debug)]
|
||||
struct Custom(i32);
|
||||
let (mut tx, rx) = super::channel::<Custom, ()>();
|
||||
@@ -191,7 +192,7 @@ mod tests {
|
||||
|
||||
Ok::<(), ()>(())
|
||||
})
|
||||
})).unwrap();
|
||||
}).wait().unwrap();
|
||||
}
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
@@ -200,18 +201,18 @@ mod tests {
|
||||
let (mut tx, mut rx) = super::channel::<i32, ()>();
|
||||
|
||||
b.iter(move || {
|
||||
block_on(future::lazy(|cx| {
|
||||
::futures::future::lazy(|| {
|
||||
let _ = tx.send(1).unwrap();
|
||||
loop {
|
||||
let async = rx.poll_next(cx).unwrap();
|
||||
if async.is_pending() {
|
||||
let async = rx.poll().unwrap();
|
||||
if async.is_not_ready() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok::<(), ()>(())
|
||||
})).unwrap();
|
||||
}).wait().unwrap();
|
||||
})
|
||||
}
|
||||
|
||||
@@ -221,11 +222,11 @@ mod tests {
|
||||
let (_tx, mut rx) = super::channel::<i32, ()>();
|
||||
|
||||
b.iter(move || {
|
||||
block_on(future::lazy(|cx| {
|
||||
assert!(rx.poll_next(cx).unwrap().is_pending());
|
||||
::futures::future::lazy(|| {
|
||||
assert!(rx.poll().unwrap().is_not_ready());
|
||||
|
||||
Ok::<(), ()>(())
|
||||
})).unwrap();
|
||||
}).wait().unwrap();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user