Skip to content
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

provide additional guidance on using join_all #2612

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion futures-util/src/future/future/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ where
fn record_waker(&self, waker_key: &mut usize, cx: &mut Context<'_>) {
let mut wakers_guard = self.notifier.wakers.lock().unwrap();

let wakers = match wakers_guard.as_mut() {
let waker_opt = wakers_guard.as_mut();
let wakers = match waker_opt {
Some(wakers) => wakers,
None => return,
};
Expand Down
15 changes: 15 additions & 0 deletions futures-util/src/future/join_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ where
/// * Only polling the specific futures that have been woken. In cases where
/// you have a lot of futures this will result in much more efficient polling.
///
/// When awaiting a collection of spawned tasks, consider iterating over them with
/// a for loop instead of using `join_all`, since `join_all` is more expensive than
/// simple iteration and will not warn you if there are errors.
///
/// This extra expense come from `join_all` being designed to work with all types of
/// futures. For most futures, simply iterating over a collection of them would make
/// the futures run sequentially. To ensure they always run at the same time,
/// `join_all` must do something significantly more complicated.
///
/// Consider using `join_all` if the following conditions are met:
/// 1. You don't want to spawn the tasks. (Usually because they are not `'static`),
/// 2. You care about getting their return values back in the same order, and you
/// can't use any of them until you have all of them, and
/// 3. You don't want any limit on the number of futures running at the same time.
///
/// # Examples
///
/// ```
Expand Down
3 changes: 2 additions & 1 deletion futures-util/src/lock/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ impl<T: ?Sized> Mutex<T> {
fn remove_waker(&self, wait_key: usize, wake_another: bool) {
if wait_key != WAIT_KEY_NONE {
let mut waiters = self.waiters.lock().unwrap();
match waiters.remove(wait_key) {
let waiter = waiters.remove(wait_key);
match waiter {
Waiter::Waiting(_) => {}
Waiter::Woken => {
// We were awoken, but then dropped before we could
Expand Down