|
3 | 3 | //! This module contains a number of functions and combinators for working |
4 | 4 | //! with `async`/`await` code. |
5 | 5 |
|
6 | | -use futures_core::{task, Future, Poll}; |
| 6 | +use futures_core::Future; |
7 | 7 | use core::marker::Unpin; |
8 | | -use core::mem::PinMut; |
9 | 8 |
|
10 | | -#[doc(hidden)] |
11 | | -pub fn assert_unpin<T: Future + Unpin>(_: &T) {} |
12 | | - |
13 | | -/// A macro which returns the result of polling a future once within the |
14 | | -/// current `async` context. |
15 | | -/// |
16 | | -/// This macro is only usable inside of `async` functions, closures, and blocks. |
17 | | -#[macro_export] |
18 | | -macro_rules! poll { |
19 | | - ($x:expr) => { |
20 | | - await!($crate::await::poll($x)) |
21 | | - } |
22 | | -} |
23 | | - |
24 | | -#[doc(hidden)] |
25 | | -pub fn poll<F: Future + Unpin>(future: F) -> impl Future<Output = Poll<F::Output>> { |
26 | | - PollOnce { future } |
27 | | -} |
28 | | - |
29 | | -#[allow(missing_debug_implementations)] |
30 | | -struct PollOnce<F: Future + Unpin> { |
31 | | - future: F, |
32 | | -} |
33 | | - |
34 | | -impl<F: Future + Unpin> Future for PollOnce<F> { |
35 | | - type Output = Poll<F::Output>; |
36 | | - fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> { |
37 | | - Poll::Ready(PinMut::new(&mut self.future).poll(cx)) |
38 | | - } |
39 | | -} |
| 9 | +#[macro_use] |
| 10 | +mod poll; |
| 11 | +pub use self::poll::*; |
40 | 12 |
|
41 | | -/// A macro which yields to the event loop once. |
42 | | -/// This is similar to returning `Poll::Pending` from a `Future::poll` implementation. |
43 | | -/// If `pending!` is used, the current task should be scheduled to receive a wakeup |
44 | | -/// when it is ready to make progress. |
45 | | -/// |
46 | | -/// This macro is only usable inside of `async` functions, closures, and blocks. |
47 | | -#[macro_export] |
48 | | -macro_rules! pending { |
49 | | - () => { |
50 | | - await!($crate::await::pending_once()) |
51 | | - } |
52 | | -} |
53 | | - |
54 | | -#[doc(hidden)] |
55 | | -pub fn pending_once() -> impl Future<Output = ()> { |
56 | | - PendingOnce { is_ready: false } |
57 | | -} |
58 | | - |
59 | | -#[allow(missing_debug_implementations)] |
60 | | -struct PendingOnce { |
61 | | - is_ready: bool, |
62 | | -} |
63 | | - |
64 | | -impl Future for PendingOnce { |
65 | | - type Output = (); |
66 | | - fn poll(mut self: PinMut<Self>, _: &mut task::Context) -> Poll<Self::Output> { |
67 | | - if self.is_ready { |
68 | | - Poll::Ready(()) |
69 | | - } else { |
70 | | - self.is_ready = true; |
71 | | - Poll::Pending |
72 | | - } |
73 | | - } |
74 | | -} |
| 13 | +#[macro_use] |
| 14 | +mod pending; |
| 15 | +pub use self::pending::*; |
75 | 16 |
|
76 | 17 | // Primary export is a macro |
77 | 18 | mod join; |
78 | 19 |
|
79 | 20 | // Primary export is a macro |
80 | 21 | mod select; |
81 | 22 |
|
| 23 | +#[doc(hidden)] |
| 24 | +pub fn assert_unpin<T: Future + Unpin>(_: &T) {} |
0 commit comments