Skip to content

Commit 08c663b

Browse files
committed
Re-export some items for select! macro
1 parent 8479bd2 commit 08c663b

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

futures-util/src/future/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ use futures_core::future::Future;
99
use futures_core::stream::Stream;
1010
use futures_core::task::{LocalWaker, Poll};
1111

12+
// re-export for `select!`
13+
#[doc(hidden)]
14+
pub use futures_core::future::FusedFuture;
15+
1216
// Primitive futures
1317
mod empty;
1418
pub use self::empty::{empty, Empty};

futures-util/src/task/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ pub use self::local_waker_ref::{local_waker_ref, local_waker_ref_from_nonlocal,
1616
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
1717
)]
1818
pub use futures_core::task::__internal::AtomicWaker;
19+
20+
// re-export for `select!`
21+
#[doc(hidden)]
22+
pub use futures_core::task::{LocalWaker, Poll};

futures-util/tests/select_next_some.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,32 @@ fn select() {
5555
assert_eq!(total, 6);
5656
});
5757
}
58+
59+
// Check that `select!` macro does not fail when importing from `futures_util`.
60+
#[test]
61+
fn futures_util_select() {
62+
use futures_util::select;
63+
64+
// Checks that even though `async_tasks` will yield a `None` and return
65+
// `is_terminated() == true` during the first poll, it manages to toggle
66+
// back to having items after a future is pushed into it during the second
67+
// poll (after pending_once completes).
68+
futures::executor::block_on(async {
69+
let mut fut = future::ready(1).pending_once();
70+
let mut async_tasks = FuturesUnordered::new();
71+
let mut total = 0;
72+
loop {
73+
select! {
74+
num = fut => {
75+
total += num;
76+
async_tasks.push(async { 5 });
77+
},
78+
num = async_tasks.select_next_some() => {
79+
total += num;
80+
}
81+
complete => break,
82+
}
83+
}
84+
assert_eq!(total, 6);
85+
});
86+
}

0 commit comments

Comments
 (0)