Skip to content

Re-export some items for select! macro #1405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions futures-util/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use futures_core::future::Future;
use futures_core::stream::Stream;
use futures_core::task::{LocalWaker, Poll};

// re-export for `select!`
#[doc(hidden)]
pub use futures_core::future::FusedFuture;

// Primitive futures
mod empty;
pub use self::empty::{empty, Empty};
Expand Down
4 changes: 4 additions & 0 deletions futures-util/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ pub use self::local_waker_ref::{local_waker_ref, local_waker_ref_from_nonlocal,
cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr"))
)]
pub use futures_core::task::__internal::AtomicWaker;

// re-export for `select!`
#[doc(hidden)]
pub use futures_core::task::{LocalWaker, Poll};
29 changes: 29 additions & 0 deletions futures-util/tests/select_next_some.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,32 @@ fn select() {
assert_eq!(total, 6);
});
}

// Check that `select!` macro does not fail when importing from `futures_util`.
#[test]
fn futures_util_select() {
use futures_util::select;

// Checks that even though `async_tasks` will yield a `None` and return
// `is_terminated() == true` during the first poll, it manages to toggle
// back to having items after a future is pushed into it during the second
// poll (after pending_once completes).
futures::executor::block_on(async {
let mut fut = future::ready(1).pending_once();
let mut async_tasks = FuturesUnordered::new();
let mut total = 0;
loop {
select! {
num = fut => {
total += num;
async_tasks.push(async { 5 });
},
num = async_tasks.select_next_some() => {
total += num;
}
complete => break,
}
}
assert_eq!(total, 6);
});
}