@@ -21,110 +21,7 @@ cfg_unstable_default! {
2121}
2222
2323extension_trait ! {
24- #[ doc = r#"
25- A future represents an asynchronous computation.
26-
27- A future is a value that may not have finished computing yet. This kind of
28- "asynchronous value" makes it possible for a thread to continue doing useful
29- work while it waits for the value to become available.
30-
31- The [provided methods] do not really exist in the trait itself, but they become
32- available when [`FutureExt`] from the [prelude] is imported:
33-
34- ```
35- # #[allow(unused_imports)]
36- use async_std::prelude::*;
37- ```
38-
39- # The `poll` method
40-
41- The core method of future, `poll`, *attempts* to resolve the future into a
42- final value. This method does not block if the value is not ready. Instead,
43- the current task is scheduled to be woken up when it's possible to make
44- further progress by `poll`ing again. The `context` passed to the `poll`
45- method can provide a [`Waker`], which is a handle for waking up the current
46- task.
47-
48- When using a future, you generally won't call `poll` directly, but instead
49- `.await` the value.
50-
51- [`Waker`]: ../task/struct.Waker.html
52- [provided methods]: #provided-methods
53- [`FutureExt`]: ../prelude/trait.FutureExt.html
54- [prelude]: ../prelude/index.html
55- "# ]
56- pub trait Future {
57- #[ doc = r#"
58- The type of value produced on completion.
59- "# ]
60- type Output ;
61-
62- #[ doc = r#"
63- Attempt to resolve the future to a final value, registering
64- the current task for wakeup if the value is not yet available.
65-
66- # Return value
67-
68- This function returns:
69-
70- - [`Poll::Pending`] if the future is not ready yet
71- - [`Poll::Ready(val)`] with the result `val` of this future if it
72- finished successfully.
73-
74- Once a future has finished, clients should not `poll` it again.
75-
76- When a future is not ready yet, `poll` returns `Poll::Pending` and
77- stores a clone of the [`Waker`] copied from the current [`Context`].
78- This [`Waker`] is then woken once the future can make progress.
79- For example, a future waiting for a socket to become
80- readable would call `.clone()` on the [`Waker`] and store it.
81- When a signal arrives elsewhere indicating that the socket is readable,
82- [`Waker::wake`] is called and the socket future's task is awoken.
83- Once a task has been woken up, it should attempt to `poll` the future
84- again, which may or may not produce a final value.
85-
86- Note that on multiple calls to `poll`, only the [`Waker`] from the
87- [`Context`] passed to the most recent call should be scheduled to
88- receive a wakeup.
89-
90- # Runtime characteristics
91-
92- Futures alone are *inert*; they must be *actively* `poll`ed to make
93- progress, meaning that each time the current task is woken up, it should
94- actively re-`poll` pending futures that it still has an interest in.
95-
96- The `poll` function is not called repeatedly in a tight loop -- instead,
97- it should only be called when the future indicates that it is ready to
98- make progress (by calling `wake()`). If you're familiar with the
99- `poll(2)` or `select(2)` syscalls on Unix it's worth noting that futures
100- typically do *not* suffer the same problems of "all wakeups must poll
101- all events"; they are more like `epoll(4)`.
102-
103- An implementation of `poll` should strive to return quickly, and should
104- not block. Returning quickly prevents unnecessarily clogging up
105- threads or event loops. If it is known ahead of time that a call to
106- `poll` may end up taking awhile, the work should be offloaded to a
107- thread pool (or something similar) to ensure that `poll` can return
108- quickly.
109-
110- # Panics
111-
112- Once a future has completed (returned `Ready` from `poll`), calling its
113- `poll` method again may panic, block forever, or cause other kinds of
114- problems; the `Future` trait places no requirements on the effects of
115- such a call. However, as the `poll` method is not marked `unsafe`,
116- Rust's usual rules apply: calls must never cause undefined behavior
117- (memory corruption, incorrect use of `unsafe` functions, or the like),
118- regardless of the future's state.
119-
120- [`Poll::Pending`]: ../task/enum.Poll.html#variant.Pending
121- [`Poll::Ready(val)`]: ../task/enum.Poll.html#variant.Ready
122- [`Context`]: ../task/struct.Context.html
123- [`Waker`]: ../task/struct.Waker.html
124- [`Waker::wake`]: ../task/struct.Waker.html#method.wake
125- "# ]
126- fn poll( self : Pin <& mut Self >, cx: & mut Context ) -> Poll <Self :: Output >;
127- }
24+ pub trait Future { }
12825
12926 #[ doc = r#"
13027 Extension methods for [`Future`].
0 commit comments