mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
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:
committed by
Carl Lerche
parent
9144b2ff53
commit
7ae010f0f3
+1
-1
@@ -74,7 +74,7 @@ jobs:
|
|||||||
parameters:
|
parameters:
|
||||||
name: async_await
|
name: async_await
|
||||||
displayName: Async / Await
|
displayName: Async / Await
|
||||||
rust: nightly-2019-02-28
|
rust: nightly-2019-04-08
|
||||||
noDefaultFeatures: ''
|
noDefaultFeatures: ''
|
||||||
benches: true
|
benches: true
|
||||||
crates:
|
crates:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use futures::{Future, Poll};
|
|||||||
use std::future::Future as StdFuture;
|
use std::future::Future as StdFuture;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::ptr;
|
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`.
|
/// Convert an 0.3 `Future` to an 0.1 `Future`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -45,8 +45,9 @@ where
|
|||||||
use futures::Async::*;
|
use futures::Async::*;
|
||||||
|
|
||||||
let waker = noop_waker();
|
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 {
|
match res {
|
||||||
StdPoll::Ready(Ok(val)) => Ok(Ready(val)),
|
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.");
|
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 {
|
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(clone_raw, wake, drop_raw);
|
||||||
clone: clone_raw,
|
|
||||||
drop: drop_raw,
|
|
||||||
wake,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use futures::{Async, Future};
|
|||||||
|
|
||||||
use std::future::Future as StdFuture;
|
use std::future::Future as StdFuture;
|
||||||
use std::pin::Pin;
|
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`.
|
/// Converts an 0.1 `Future` into an 0.3 `Future`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -53,7 +53,7 @@ where
|
|||||||
{
|
{
|
||||||
type Output = Result<T::Item, T::Error>;
|
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};
|
use futures::Async::{NotReady, Ready};
|
||||||
|
|
||||||
// TODO: wire in cx
|
// TODO: wire in cx
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use tokio_io::AsyncWrite;
|
|||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Poll, Waker};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
/// A future used to fully flush an I/O object.
|
/// A future used to fully flush an I/O object.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -23,7 +23,7 @@ impl<'a, T: AsyncWrite + ?Sized> Flush<'a, T> {
|
|||||||
impl<'a, T: AsyncWrite + ?Sized> Future for Flush<'a, T> {
|
impl<'a, T: AsyncWrite + ?Sized> Future for Flush<'a, T> {
|
||||||
type Output = io::Result<()>;
|
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;
|
use crate::compat::forward::convert_poll;
|
||||||
convert_poll(self.writer.poll_flush())
|
convert_poll(self.writer.poll_flush())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ impl<'a, T: AsyncRead + ?Sized> Read<'a, T> {
|
|||||||
impl<'a, T: AsyncRead + ?Sized> Future for Read<'a, T> {
|
impl<'a, T: AsyncRead + ?Sized> Future for Read<'a, T> {
|
||||||
type Output = io::Result<usize>;
|
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;
|
use crate::compat::forward::convert_poll;
|
||||||
|
|
||||||
let this = &mut *self;
|
let this = &mut *self;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ fn eof() -> io::Error {
|
|||||||
impl<'a, T: AsyncRead + ?Sized> Future for ReadExact<'a, T> {
|
impl<'a, T: AsyncRead + ?Sized> Future for ReadExact<'a, T> {
|
||||||
type Output = io::Result<()>;
|
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;
|
use crate::compat::forward::convert_poll;
|
||||||
|
|
||||||
let this = &mut *self;
|
let this = &mut *self;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ impl<'a, T: AsyncWrite + ?Sized> Write<'a, T> {
|
|||||||
impl<'a, T: AsyncWrite + ?Sized> Future for Write<'a, T> {
|
impl<'a, T: AsyncWrite + ?Sized> Future for Write<'a, T> {
|
||||||
type Output = io::Result<usize>;
|
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;
|
use crate::compat::forward::convert_poll;
|
||||||
|
|
||||||
let this = &mut *self;
|
let this = &mut *self;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ fn zero_write() -> io::Error {
|
|||||||
impl<'a, T: AsyncWrite + ?Sized> Future for WriteAll<'a, T> {
|
impl<'a, T: AsyncWrite + ?Sized> Future for WriteAll<'a, T> {
|
||||||
type Output = io::Result<()>;
|
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;
|
use crate::compat::forward::convert_poll;
|
||||||
|
|
||||||
let this = &mut *self;
|
let this = &mut *self;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ impl<'a, T: Sink + Unpin + ?Sized> Send<'a, T> {
|
|||||||
impl<T: Sink + Unpin + ?Sized> Future for Send<'_, T> {
|
impl<T: Sink + Unpin + ?Sized> Future for Send<'_, T> {
|
||||||
type Output = Result<(), T::SinkError>;
|
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 crate::compat::forward::convert_poll;
|
||||||
use futures::AsyncSink::{NotReady, Ready};
|
use futures::AsyncSink::{NotReady, Ready};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use futures::Stream;
|
|||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Poll, Waker};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
/// A future of the next element of a stream.
|
/// A future of the next element of a stream.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -21,7 +21,7 @@ impl<'a, T: Stream + Unpin> Next<'a, T> {
|
|||||||
impl<'a, T: Stream + Unpin> Future for Next<'a, T> {
|
impl<'a, T: Stream + Unpin> Future for Next<'a, T> {
|
||||||
type Output = Option<Result<T::Item, T::Error>>;
|
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;
|
use crate::compat::forward::convert_poll_stream;
|
||||||
|
|
||||||
convert_poll_stream(self.stream.poll())
|
convert_poll_stream(self.stream.poll())
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::future::Future as StdFuture;
|
use std::future::Future as StdFuture;
|
||||||
use std::pin::Pin;
|
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<(), ()>> {
|
fn map_ok<T: StdFuture>(future: T) -> impl StdFuture<Output = Result<(), ()>> {
|
||||||
MapOk(future)
|
MapOk(future)
|
||||||
@@ -17,8 +17,8 @@ impl<T> MapOk<T> {
|
|||||||
impl<T: StdFuture> StdFuture for MapOk<T> {
|
impl<T: StdFuture> StdFuture for MapOk<T> {
|
||||||
type Output = Result<(), ()>;
|
type Output = Result<(), ()>;
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, context: &mut Context) -> Poll<Self::Output> {
|
||||||
match self.future().poll(waker) {
|
match self.future().poll(context) {
|
||||||
Poll::Ready(_) => Poll::Ready(Ok(())),
|
Poll::Ready(_) => Poll::Ready(Ok(())),
|
||||||
Poll::Pending => Poll::Pending,
|
Poll::Pending => Poll::Pending,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user