Skip to content

Commit ee0dc8f

Browse files
Extract contents of await module into submodules
1 parent 824a29f commit ee0dc8f

File tree

3 files changed

+77
-66
lines changed

3 files changed

+77
-66
lines changed

futures-util/src/await/mod.rs

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,22 @@
33
//! This module contains a number of functions and combinators for working
44
//! with `async`/`await` code.
55
6-
use futures_core::{task, Future, Poll};
6+
use futures_core::Future;
77
use core::marker::Unpin;
8-
use core::mem::PinMut;
98

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::*;
4012

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::*;
7516

7617
// Primary export is a macro
7718
mod join;
7819

7920
// Primary export is a macro
8021
mod select;
8122

23+
#[doc(hidden)]
24+
pub fn assert_unpin<T: Future + Unpin>(_: &T) {}

futures-util/src/await/pending.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use futures_core::{task, Future, Poll};
2+
use core::mem::PinMut;
3+
4+
/// A macro which yields to the event loop once.
5+
/// This is similar to returning `Poll::Pending` from a `Future::poll` implementation.
6+
/// If `pending!` is used, the current task should be scheduled to receive a wakeup
7+
/// when it is ready to make progress.
8+
///
9+
/// This macro is only usable inside of `async` functions, closures, and blocks.
10+
#[macro_export]
11+
macro_rules! pending {
12+
() => {
13+
await!($crate::await::pending_once())
14+
}
15+
}
16+
17+
#[doc(hidden)]
18+
pub fn pending_once() -> PendingOnce {
19+
PendingOnce { is_ready: false }
20+
}
21+
22+
#[allow(missing_debug_implementations)]
23+
pub struct PendingOnce {
24+
is_ready: bool,
25+
}
26+
27+
impl Future for PendingOnce {
28+
type Output = ();
29+
fn poll(mut self: PinMut<Self>, _: &mut task::Context) -> Poll<Self::Output> {
30+
if self.is_ready {
31+
Poll::Ready(())
32+
} else {
33+
self.is_ready = true;
34+
Poll::Pending
35+
}
36+
}
37+
}

futures-util/src/await/poll.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use futures_core::{task, Future, Poll};
2+
use core::marker::Unpin;
3+
use core::mem::PinMut;
4+
5+
/// A macro which returns the result of polling a future once within the
6+
/// current `async` context.
7+
///
8+
/// This macro is only usable inside of `async` functions, closures, and blocks.
9+
#[macro_export]
10+
macro_rules! poll {
11+
($x:expr) => {
12+
await!($crate::await::poll($x))
13+
}
14+
}
15+
16+
#[doc(hidden)]
17+
pub fn poll<F: Future + Unpin>(future: F) -> PollOnce<F> {
18+
PollOnce { future }
19+
}
20+
21+
#[allow(missing_debug_implementations)]
22+
pub struct PollOnce<F: Future + Unpin> {
23+
future: F,
24+
}
25+
26+
impl<F: Future + Unpin> Future for PollOnce<F> {
27+
type Output = Poll<F::Output>;
28+
fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> {
29+
Poll::Ready(PinMut::new(&mut self.future).poll(cx))
30+
}
31+
}

0 commit comments

Comments
 (0)