Skip to content

Commit d9a4b22

Browse files
committed
Update the future/task API
This change updates the future and task API as discussed in the stabilization RFC at rust-lang/rfcs#2592. Changes: - Replacing UnsafeWake with RawWaker and RawWakerVtable - Removal of LocalWaker - Removal of Arc-based Wake trait
1 parent 4f4f4a4 commit d9a4b22

File tree

9 files changed

+111
-411
lines changed

9 files changed

+111
-411
lines changed

src/liballoc/boxed.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use core::ops::{
7171
CoerceUnsized, DispatchFromDyn, Deref, DerefMut, Receiver, Generator, GeneratorState
7272
};
7373
use core::ptr::{self, NonNull, Unique};
74-
use core::task::{LocalWaker, Poll};
74+
use core::task::{Waker, Poll};
7575

7676
use crate::vec::Vec;
7777
use crate::raw_vec::RawVec;
@@ -896,7 +896,7 @@ impl<G: ?Sized + Generator> Generator for Pin<Box<G>> {
896896
impl<F: ?Sized + Future + Unpin> Future for Box<F> {
897897
type Output = F::Output;
898898

899-
fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output> {
900-
F::poll(Pin::new(&mut *self), lw)
899+
fn poll(mut self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
900+
F::poll(Pin::new(&mut *self), waker)
901901
}
902902
}

src/liballoc/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ mod macros;
133133

134134
pub mod alloc;
135135

136-
#[unstable(feature = "futures_api",
137-
reason = "futures in libcore are unstable",
138-
issue = "50547")]
139-
pub mod task;
140136
// Primitive types using the heaps above
141137

142138
// Need to conditionally define the mod from `boxed.rs` to avoid

src/liballoc/task.rs

Lines changed: 0 additions & 130 deletions
This file was deleted.

src/libcore/future/future.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use marker::Unpin;
66
use ops;
77
use pin::Pin;
8-
use task::{Poll, LocalWaker};
8+
use task::{Poll, Waker};
99

1010
/// A future represents an asynchronous computation.
1111
///
@@ -25,7 +25,7 @@ use task::{Poll, LocalWaker};
2525
/// `await!` the value.
2626
#[must_use = "futures do nothing unless polled"]
2727
pub trait Future {
28-
/// The result of the `Future`.
28+
/// The type of value produced on completion.
2929
type Output;
3030

3131
/// Attempt to resolve the future to a final value, registering
@@ -42,16 +42,16 @@ pub trait Future {
4242
/// Once a future has finished, clients should not `poll` it again.
4343
///
4444
/// When a future is not ready yet, `poll` returns `Poll::Pending` and
45-
/// stores a clone of the [`LocalWaker`] to be woken once the future can
45+
/// stores a clone of the [`Waker`] to be woken once the future can
4646
/// make progress. For example, a future waiting for a socket to become
47-
/// readable would call `.clone()` on the [`LocalWaker`] and store it.
47+
/// readable would call `.clone()` on the [`Waker`] and store it.
4848
/// When a signal arrives elsewhere indicating that the socket is readable,
49-
/// `[LocalWaker::wake]` is called and the socket future's task is awoken.
49+
/// `[Waker::wake]` is called and the socket future's task is awoken.
5050
/// Once a task has been woken up, it should attempt to `poll` the future
5151
/// again, which may or may not produce a final value.
5252
///
5353
/// Note that on multiple calls to `poll`, only the most recent
54-
/// [`LocalWaker`] passed to `poll` should be scheduled to receive a
54+
/// [`Waker`] passed to `poll` should be scheduled to receive a
5555
/// wakeup.
5656
///
5757
/// # Runtime characteristics
@@ -74,16 +74,6 @@ pub trait Future {
7474
/// thread pool (or something similar) to ensure that `poll` can return
7575
/// quickly.
7676
///
77-
/// # [`LocalWaker`], [`Waker`] and thread-safety
78-
///
79-
/// The `poll` function takes a [`LocalWaker`], an object which knows how to
80-
/// awaken the current task. [`LocalWaker`] is not `Send` nor `Sync`, so in
81-
/// order to make thread-safe futures the [`LocalWaker::into_waker`] method
82-
/// should be used to convert the [`LocalWaker`] into a thread-safe version.
83-
/// [`LocalWaker::wake`] implementations have the ability to be more
84-
/// efficient, however, so when thread safety is not necessary,
85-
/// [`LocalWaker`] should be preferred.
86-
///
8777
/// # Panics
8878
///
8979
/// Once a future has completed (returned `Ready` from `poll`),
@@ -93,18 +83,16 @@ pub trait Future {
9383
///
9484
/// [`Poll::Pending`]: ../task/enum.Poll.html#variant.Pending
9585
/// [`Poll::Ready(val)`]: ../task/enum.Poll.html#variant.Ready
96-
/// [`LocalWaker`]: ../task/struct.LocalWaker.html
97-
/// [`LocalWaker::into_waker`]: ../task/struct.LocalWaker.html#method.into_waker
98-
/// [`LocalWaker::wake`]: ../task/struct.LocalWaker.html#method.wake
9986
/// [`Waker`]: ../task/struct.Waker.html
100-
fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output>;
87+
/// [`Waker::wake`]: ../task/struct.Waker.html#method.wake
88+
fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output>;
10189
}
10290

10391
impl<'a, F: ?Sized + Future + Unpin> Future for &'a mut F {
10492
type Output = F::Output;
10593

106-
fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output> {
107-
F::poll(Pin::new(&mut **self), lw)
94+
fn poll(mut self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
95+
F::poll(Pin::new(&mut **self), waker)
10896
}
10997
}
11098

@@ -115,7 +103,7 @@ where
115103
{
116104
type Output = <<P as ops::Deref>::Target as Future>::Output;
117105

118-
fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output> {
119-
Pin::get_mut(self).as_mut().poll(lw)
106+
fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
107+
Pin::get_mut(self).as_mut().poll(waker)
120108
}
121109
}

src/libcore/task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ mod poll;
88
pub use self::poll::Poll;
99

1010
mod wake;
11-
pub use self::wake::{Waker, LocalWaker, UnsafeWake};
11+
pub use self::wake::{Waker, RawWaker, RawWakerVTable};

0 commit comments

Comments
 (0)