async-await: Use Context instead of Waker in poll (#1041)

Rust nightly std::future::Future recently changed Waker
to Context.

Change to use Context

Co-Authored-By: Kintaro <[email protected]>
This commit is contained in:
Simon Wollwage
2019-04-10 09:14:31 -07:00
committed by Carl Lerche
parent 9144b2ff53
commit 7ae010f0f3
11 changed files with 19 additions and 22 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ jobs:
parameters:
name: async_await
displayName: Async / Await
rust: nightly-2019-02-28
rust: nightly-2019-04-08
noDefaultFeatures: ''
benches: true
crates:
+4 -7
View File
@@ -3,7 +3,7 @@ use futures::{Future, Poll};
use std::future::Future as StdFuture;
use std::pin::Pin;
use std::ptr;
use std::task::{Poll as StdPoll, RawWaker, RawWakerVTable, Waker};
use std::task::{Context, Poll as StdPoll, RawWaker, RawWakerVTable, Waker};
/// Convert an 0.3 `Future` to an 0.1 `Future`.
#[derive(Debug)]
@@ -45,8 +45,9 @@ where
use futures::Async::*;
let waker = noop_waker();
let mut context = Context::from_waker(&waker);
let res = self.0.as_mut().poll(&waker);
let res = self.0.as_mut().poll(&mut context);
match res {
StdPoll::Ready(Ok(val)) => Ok(Ready(val)),
@@ -76,8 +77,4 @@ unsafe fn wake(_data: *const ()) {
unimplemented!("async-await-preview currently only supports futures 0.1. Use the compatibility layer of futures 0.3 instead, if you want to use futures 0.3.");
}
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable {
clone: clone_raw,
drop: drop_raw,
wake,
};
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(clone_raw, wake, drop_raw);
+2 -2
View File
@@ -2,7 +2,7 @@ use futures::{Async, Future};
use std::future::Future as StdFuture;
use std::pin::Pin;
use std::task::{Poll as StdPoll, Waker};
use std::task::{Context, Poll as StdPoll};
/// Converts an 0.1 `Future` into an 0.3 `Future`.
#[derive(Debug)]
@@ -53,7 +53,7 @@ where
{
type Output = Result<T::Item, T::Error>;
fn poll(mut self: Pin<&mut Self>, _waker: &Waker) -> StdPoll<Self::Output> {
fn poll(mut self: Pin<&mut Self>, _context: &mut Context) -> StdPoll<Self::Output> {
use futures::Async::{NotReady, Ready};
// TODO: wire in cx
+2 -2
View File
@@ -3,7 +3,7 @@ use tokio_io::AsyncWrite;
use std::future::Future;
use std::io;
use std::pin::Pin;
use std::task::{Poll, Waker};
use std::task::{Context, Poll};
/// A future used to fully flush an I/O object.
#[derive(Debug)]
@@ -23,7 +23,7 @@ impl<'a, T: AsyncWrite + ?Sized> Flush<'a, T> {
impl<'a, T: AsyncWrite + ?Sized> Future for Flush<'a, T> {
type Output = io::Result<()>;
fn poll(mut self: Pin<&mut Self>, _wx: &Waker) -> Poll<Self::Output> {
fn poll(mut self: Pin<&mut Self>, _context: &mut Context) -> Poll<Self::Output> {
use crate::compat::forward::convert_poll;
convert_poll(self.writer.poll_flush())
}
+1 -1
View File
@@ -25,7 +25,7 @@ impl<'a, T: AsyncRead + ?Sized> Read<'a, T> {
impl<'a, T: AsyncRead + ?Sized> Future for Read<'a, T> {
type Output = io::Result<usize>;
fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll<Self::Output> {
fn poll(mut self: Pin<&mut Self>, _context: &mut task::Context) -> Poll<Self::Output> {
use crate::compat::forward::convert_poll;
let this = &mut *self;
+1 -1
View File
@@ -30,7 +30,7 @@ fn eof() -> io::Error {
impl<'a, T: AsyncRead + ?Sized> Future for ReadExact<'a, T> {
type Output = io::Result<()>;
fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll<Self::Output> {
fn poll(mut self: Pin<&mut Self>, _context: &mut task::Context) -> Poll<Self::Output> {
use crate::compat::forward::convert_poll;
let this = &mut *self;
+1 -1
View File
@@ -25,7 +25,7 @@ impl<'a, T: AsyncWrite + ?Sized> Write<'a, T> {
impl<'a, T: AsyncWrite + ?Sized> Future for Write<'a, T> {
type Output = io::Result<usize>;
fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll<io::Result<usize>> {
fn poll(mut self: Pin<&mut Self>, _context: &mut task::Context) -> Poll<io::Result<usize>> {
use crate::compat::forward::convert_poll;
let this = &mut *self;
+1 -1
View File
@@ -30,7 +30,7 @@ fn zero_write() -> io::Error {
impl<'a, T: AsyncWrite + ?Sized> Future for WriteAll<'a, T> {
type Output = io::Result<()>;
fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll<io::Result<()>> {
fn poll(mut self: Pin<&mut Self>, _context: &mut task::Context) -> Poll<io::Result<()>> {
use crate::compat::forward::convert_poll;
let this = &mut *self;
+1 -1
View File
@@ -27,7 +27,7 @@ impl<'a, T: Sink + Unpin + ?Sized> Send<'a, T> {
impl<T: Sink + Unpin + ?Sized> Future for Send<'_, T> {
type Output = Result<(), T::SinkError>;
fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll<Self::Output> {
fn poll(mut self: Pin<&mut Self>, _context: &mut task::Context) -> Poll<Self::Output> {
use crate::compat::forward::convert_poll;
use futures::AsyncSink::{NotReady, Ready};
+2 -2
View File
@@ -2,7 +2,7 @@ use futures::Stream;
use std::future::Future;
use std::pin::Pin;
use std::task::{Poll, Waker};
use std::task::{Context, Poll};
/// A future of the next element of a stream.
#[derive(Debug)]
@@ -21,7 +21,7 @@ impl<'a, T: Stream + Unpin> Next<'a, T> {
impl<'a, T: Stream + Unpin> Future for Next<'a, T> {
type Output = Option<Result<T::Item, T::Error>>;
fn poll(mut self: Pin<&mut Self>, _waker: &Waker) -> Poll<Self::Output> {
fn poll(mut self: Pin<&mut Self>, _context: &mut Context) -> Poll<Self::Output> {
use crate::compat::forward::convert_poll_stream;
convert_poll_stream(self.stream.poll())
+3 -3
View File
@@ -1,6 +1,6 @@
use std::future::Future as StdFuture;
use std::pin::Pin;
use std::task::{Poll, Waker};
use std::task::{Context, Poll};
fn map_ok<T: StdFuture>(future: T) -> impl StdFuture<Output = Result<(), ()>> {
MapOk(future)
@@ -17,8 +17,8 @@ impl<T> MapOk<T> {
impl<T: StdFuture> StdFuture for MapOk<T> {
type Output = Result<(), ()>;
fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
match self.future().poll(waker) {
fn poll(self: Pin<&mut Self>, context: &mut Context) -> Poll<Self::Output> {
match self.future().poll(context) {
Poll::Ready(_) => Poll::Ready(Ok(())),
Poll::Pending => Poll::Pending,
}