Skip to content
This repository was archived by the owner on Oct 9, 2019. It is now read-only.

Commit c7765c0

Browse files
authored
compat with new futures (#1)
* compat with new futures Signed-off-by: Yoshua Wuyts <[email protected]> * fixes Signed-off-by: Yoshua Wuyts <[email protected]> * fix tests Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent b83b7d1 commit c7765c0

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ edition = "2018"
1414
[dependencies]
1515

1616
[dev-dependencies]
17-
futures-preview = "0.3.0-alpha.13"
17+
futures-preview = "0.3.0-alpha.14"

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ __Basic usage__
1515
#![feature(futures_api)]
1616

1717
use std::pin::Pin;
18-
use std::task::{Poll, Waker};
18+
use std::task::{Context, Poll};
1919
use futures::prelude::*;
2020
use async_ready::AsyncReady;
2121
use std::io;
@@ -24,7 +24,7 @@ struct Fut;
2424

2525
impl Future for Fut {
2626
type Output = ();
27-
fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
27+
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
2828
Poll::Ready(())
2929
}
3030
}
@@ -33,8 +33,10 @@ impl AsyncReady for Fut {
3333
type Ok = ();
3434
type Err = io::Error;
3535

36-
fn poll_ready(&mut self, waker: &Waker)
37-
-> Poll<Result<Self::Ok, Self::Err>> {
36+
fn poll_ready(
37+
mut self: Pin<&mut Self>,
38+
cx: &mut Context<'_>,
39+
) -> Poll<Result<Self::Ok, Self::Err>> {
3840
Poll::Ready(Ok(()))
3941
}
4042
}

src/lib.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! #![feature(futures_api)]
1313
//!
1414
//! use std::pin::Pin;
15-
//! use std::task::{Poll, Waker};
15+
//! use std::task::{Context, Poll};
1616
//! use futures::prelude::*;
1717
//! use async_ready::AsyncReady;
1818
//! use std::io;
@@ -21,7 +21,7 @@
2121
//!
2222
//! impl Future for Fut {
2323
//! type Output = ();
24-
//! fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
24+
//! fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
2525
//! Poll::Ready(())
2626
//! }
2727
//! }
@@ -30,16 +30,19 @@
3030
//! type Ok = ();
3131
//! type Err = io::Error;
3232
//!
33-
//! fn poll_ready(&mut self, waker: &Waker)
34-
//! -> Poll<Result<Self::Ok, Self::Err>> {
33+
//! fn poll_ready(
34+
//! mut self: Pin<&mut Self>,
35+
//! cx: &mut Context<'_>,
36+
//! ) -> Poll<Result<Self::Ok, Self::Err>> {
3537
//! Poll::Ready(Ok(()))
3638
//! }
3739
//! }
3840
//! ```
3941
4042
#![feature(futures_api)]
4143

42-
use std::task::{Poll, Waker};
44+
use std::pin::Pin;
45+
use std::task::{Context, Poll};
4346

4447
/// Determine if the underlying API can be written to.
4548
pub trait AsyncWriteReady {
@@ -50,7 +53,10 @@ pub trait AsyncWriteReady {
5053
type Err: std::error::Error + Send + Sync;
5154

5255
/// Check if the underlying API can be written to.
53-
fn poll_write_ready(&self, waker: &Waker) -> Poll<Result<Self::Ok, Self::Err>>;
56+
fn poll_write_ready(
57+
self: Pin<&mut Self>,
58+
cx: &mut Context<'_>,
59+
) -> Poll<Result<Self::Ok, Self::Err>>;
5460
}
5561

5662
/// Determine if the underlying API can be read from.
@@ -62,7 +68,10 @@ pub trait AsyncReadReady {
6268
type Err: std::error::Error + Send + Sync;
6369

6470
/// Check if the underlying API can be read from.
65-
fn poll_read_ready(&self, waker: &Waker) -> Poll<Result<Self::Ok, Self::Err>>;
71+
fn poll_read_ready(
72+
self: Pin<&mut Self>,
73+
cx: &mut Context<'_>,
74+
) -> Poll<Result<Self::Ok, Self::Err>>;
6675
}
6776

6877
/// Determine if a struct is async-ready to yield futures.
@@ -81,7 +90,10 @@ pub trait AsyncReady {
8190
type Err: std::error::Error + Send + Sync;
8291

8392
/// Check if the stream can be read from.
84-
fn poll_ready(&self, waker: &Waker) -> Poll<Result<Self::Ok, Self::Err>>;
93+
fn poll_ready(
94+
self: Pin<&mut Self>,
95+
cx: &mut Context<'_>,
96+
) -> Poll<Result<Self::Ok, Self::Err>>;
8597
}
8698

8799
/// Extract an error from the underlying struct that isn't propagated through

0 commit comments

Comments
 (0)