5
5
use marker:: Unpin ;
6
6
use ops;
7
7
use pin:: Pin ;
8
- use task:: { Poll , LocalWaker } ;
8
+ use task:: { Poll , Waker } ;
9
9
10
10
/// A future represents an asynchronous computation.
11
11
///
@@ -19,13 +19,14 @@ use task::{Poll, LocalWaker};
19
19
/// final value. This method does not block if the value is not ready. Instead,
20
20
/// the current task is scheduled to be woken up when it's possible to make
21
21
/// further progress by `poll`ing again. The wake up is performed using
22
- /// `cx.waker()`, a handle for waking up the current task.
22
+ /// the `waker` argument of the `poll()` method, which is a handle for waking
23
+ /// up the current task.
23
24
///
24
25
/// When using a future, you generally won't call `poll` directly, but instead
25
26
/// `await!` the value.
26
27
#[ must_use = "futures do nothing unless polled" ]
27
28
pub trait Future {
28
- /// The result of the `Future` .
29
+ /// The type of value produced on completion .
29
30
type Output ;
30
31
31
32
/// Attempt to resolve the future to a final value, registering
@@ -42,16 +43,16 @@ pub trait Future {
42
43
/// Once a future has finished, clients should not `poll` it again.
43
44
///
44
45
/// 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
46
+ /// stores a clone of the [`Waker `] to be woken once the future can
46
47
/// make progress. For example, a future waiting for a socket to become
47
- /// readable would call `.clone()` on the [`LocalWaker `] and store it.
48
+ /// readable would call `.clone()` on the [`Waker `] and store it.
48
49
/// When a signal arrives elsewhere indicating that the socket is readable,
49
- /// `[LocalWaker ::wake]` is called and the socket future's task is awoken.
50
+ /// `[Waker ::wake]` is called and the socket future's task is awoken.
50
51
/// Once a task has been woken up, it should attempt to `poll` the future
51
52
/// again, which may or may not produce a final value.
52
53
///
53
54
/// Note that on multiple calls to `poll`, only the most recent
54
- /// [`LocalWaker `] passed to `poll` should be scheduled to receive a
55
+ /// [`Waker `] passed to `poll` should be scheduled to receive a
55
56
/// wakeup.
56
57
///
57
58
/// # Runtime characteristics
@@ -67,44 +68,35 @@ pub trait Future {
67
68
/// typically do *not* suffer the same problems of "all wakeups must poll
68
69
/// all events"; they are more like `epoll(4)`.
69
70
///
70
- /// An implementation of `poll` should strive to return quickly, and must
71
- /// *never* block. Returning quickly prevents unnecessarily clogging up
71
+ /// An implementation of `poll` should strive to return quickly, and should
72
+ /// not block. Returning quickly prevents unnecessarily clogging up
72
73
/// threads or event loops. If it is known ahead of time that a call to
73
74
/// `poll` may end up taking awhile, the work should be offloaded to a
74
75
/// thread pool (or something similar) to ensure that `poll` can return
75
76
/// quickly.
76
77
///
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.
78
+ /// An implementation of `poll` may also never cause memory unsafety.
86
79
///
87
80
/// # Panics
88
81
///
89
82
/// Once a future has completed (returned `Ready` from `poll`),
90
83
/// then any future calls to `poll` may panic, block forever, or otherwise
91
- /// cause bad behavior. The `Future` trait itself provides no guarantees
92
- /// about the behavior of `poll` after a future has completed.
84
+ /// cause any kind of bad behavior expect causing memory unsafety.
85
+ /// The `Future` trait itself provides no guarantees about the behavior
86
+ /// of `poll` after a future has completed.
93
87
///
94
88
/// [`Poll::Pending`]: ../task/enum.Poll.html#variant.Pending
95
89
/// [`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
99
90
/// [`Waker`]: ../task/struct.Waker.html
100
- fn poll ( self : Pin < & mut Self > , lw : & LocalWaker ) -> Poll < Self :: Output > ;
91
+ /// [`Waker::wake`]: ../task/struct.Waker.html#method.wake
92
+ fn poll ( self : Pin < & mut Self > , waker : & Waker ) -> Poll < Self :: Output > ;
101
93
}
102
94
103
95
impl < ' a , F : ?Sized + Future + Unpin > Future for & ' a mut F {
104
96
type Output = F :: Output ;
105
97
106
- fn poll ( mut self : Pin < & mut Self > , lw : & LocalWaker ) -> Poll < Self :: Output > {
107
- F :: poll ( Pin :: new ( & mut * * self ) , lw )
98
+ fn poll ( mut self : Pin < & mut Self > , waker : & Waker ) -> Poll < Self :: Output > {
99
+ F :: poll ( Pin :: new ( & mut * * self ) , waker )
108
100
}
109
101
}
110
102
@@ -115,7 +107,7 @@ where
115
107
{
116
108
type Output = <<P as ops:: Deref >:: Target as Future >:: Output ;
117
109
118
- fn poll ( self : Pin < & mut Self > , lw : & LocalWaker ) -> Poll < Self :: Output > {
119
- Pin :: get_mut ( self ) . as_mut ( ) . poll ( lw )
110
+ fn poll ( self : Pin < & mut Self > , waker : & Waker ) -> Poll < Self :: Output > {
111
+ Pin :: get_mut ( self ) . as_mut ( ) . poll ( waker )
120
112
}
121
113
}
0 commit comments