From 7ae010f0f3b22d1f3c9bc47732988b2e35fcf253 Mon Sep 17 00:00:00 2001 From: Simon Wollwage Date: Thu, 11 Apr 2019 01:14:31 +0900 Subject: [PATCH] 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 --- azure-pipelines.yml | 2 +- tokio-async-await/src/compat/backward.rs | 11 ++++------- tokio-async-await/src/compat/forward.rs | 4 ++-- tokio-async-await/src/io/flush.rs | 4 ++-- tokio-async-await/src/io/read.rs | 2 +- tokio-async-await/src/io/read_exact.rs | 2 +- tokio-async-await/src/io/write.rs | 2 +- tokio-async-await/src/io/write_all.rs | 2 +- tokio-async-await/src/sink/send.rs | 2 +- tokio-async-await/src/stream/next.rs | 4 ++-- tokio/src/async_await.rs | 6 +++--- 11 files changed, 19 insertions(+), 22 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e15e5c557..54dc78f3d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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: diff --git a/tokio-async-await/src/compat/backward.rs b/tokio-async-await/src/compat/backward.rs index c84969bff..9529afc36 100644 --- a/tokio-async-await/src/compat/backward.rs +++ b/tokio-async-await/src/compat/backward.rs @@ -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); diff --git a/tokio-async-await/src/compat/forward.rs b/tokio-async-await/src/compat/forward.rs index 1a629db66..e373ca404 100644 --- a/tokio-async-await/src/compat/forward.rs +++ b/tokio-async-await/src/compat/forward.rs @@ -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; - fn poll(mut self: Pin<&mut Self>, _waker: &Waker) -> StdPoll { + fn poll(mut self: Pin<&mut Self>, _context: &mut Context) -> StdPoll { use futures::Async::{NotReady, Ready}; // TODO: wire in cx diff --git a/tokio-async-await/src/io/flush.rs b/tokio-async-await/src/io/flush.rs index 17d6b2d6f..4920581d7 100644 --- a/tokio-async-await/src/io/flush.rs +++ b/tokio-async-await/src/io/flush.rs @@ -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 { + fn poll(mut self: Pin<&mut Self>, _context: &mut Context) -> Poll { use crate::compat::forward::convert_poll; convert_poll(self.writer.poll_flush()) } diff --git a/tokio-async-await/src/io/read.rs b/tokio-async-await/src/io/read.rs index a54e91879..08a441bc8 100644 --- a/tokio-async-await/src/io/read.rs +++ b/tokio-async-await/src/io/read.rs @@ -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; - fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll { + fn poll(mut self: Pin<&mut Self>, _context: &mut task::Context) -> Poll { use crate::compat::forward::convert_poll; let this = &mut *self; diff --git a/tokio-async-await/src/io/read_exact.rs b/tokio-async-await/src/io/read_exact.rs index f0f84c16a..931fc4cae 100644 --- a/tokio-async-await/src/io/read_exact.rs +++ b/tokio-async-await/src/io/read_exact.rs @@ -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 { + fn poll(mut self: Pin<&mut Self>, _context: &mut task::Context) -> Poll { use crate::compat::forward::convert_poll; let this = &mut *self; diff --git a/tokio-async-await/src/io/write.rs b/tokio-async-await/src/io/write.rs index 93ffdd71b..ca62c943d 100644 --- a/tokio-async-await/src/io/write.rs +++ b/tokio-async-await/src/io/write.rs @@ -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; - fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll> { + fn poll(mut self: Pin<&mut Self>, _context: &mut task::Context) -> Poll> { use crate::compat::forward::convert_poll; let this = &mut *self; diff --git a/tokio-async-await/src/io/write_all.rs b/tokio-async-await/src/io/write_all.rs index 6b7963c15..172337e05 100644 --- a/tokio-async-await/src/io/write_all.rs +++ b/tokio-async-await/src/io/write_all.rs @@ -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> { + fn poll(mut self: Pin<&mut Self>, _context: &mut task::Context) -> Poll> { use crate::compat::forward::convert_poll; let this = &mut *self; diff --git a/tokio-async-await/src/sink/send.rs b/tokio-async-await/src/sink/send.rs index c33948a45..dd8b58adf 100644 --- a/tokio-async-await/src/sink/send.rs +++ b/tokio-async-await/src/sink/send.rs @@ -27,7 +27,7 @@ impl<'a, T: Sink + Unpin + ?Sized> Send<'a, T> { impl Future for Send<'_, T> { type Output = Result<(), T::SinkError>; - fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll { + fn poll(mut self: Pin<&mut Self>, _context: &mut task::Context) -> Poll { use crate::compat::forward::convert_poll; use futures::AsyncSink::{NotReady, Ready}; diff --git a/tokio-async-await/src/stream/next.rs b/tokio-async-await/src/stream/next.rs index 69197188a..7cd4eafa4 100644 --- a/tokio-async-await/src/stream/next.rs +++ b/tokio-async-await/src/stream/next.rs @@ -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>; - fn poll(mut self: Pin<&mut Self>, _waker: &Waker) -> Poll { + fn poll(mut self: Pin<&mut Self>, _context: &mut Context) -> Poll { use crate::compat::forward::convert_poll_stream; convert_poll_stream(self.stream.poll()) diff --git a/tokio/src/async_await.rs b/tokio/src/async_await.rs index 4530283cc..605d92644 100644 --- a/tokio/src/async_await.rs +++ b/tokio/src/async_await.rs @@ -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(future: T) -> impl StdFuture> { MapOk(future) @@ -17,8 +17,8 @@ impl MapOk { impl StdFuture for MapOk { type Output = Result<(), ()>; - fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll { - match self.future().poll(waker) { + fn poll(self: Pin<&mut Self>, context: &mut Context) -> Poll { + match self.future().poll(context) { Poll::Ready(_) => Poll::Ready(Ok(())), Poll::Pending => Poll::Pending, }