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

Drop futures as soon as they're done for array::join #138

Merged
merged 6 commits into from
Jun 12, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
slim down code branches
  • Loading branch information
yoshuawuyts committed Jun 12, 2023
commit 0d27cd839e541cfd75596f2a3b0de79b4e85acac
9 changes: 3 additions & 6 deletions src/future/join/array.rs
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ where
let mut cx = Context::from_waker(this.wakers.get(i).unwrap());

// Poll the future
// SAFETY: we checked the future state was "pending"
// SAFETY: the future's state was "pending", so it's safe to poll
if let Poll::Ready(value) = unsafe {
fut.as_mut()
.map_unchecked_mut(|t| t.deref_mut())
@@ -113,11 +113,8 @@ where
this.items[i] = MaybeUninit::new(value);
this.state[i].set_ready();
*this.pending -= 1;
}

// If the state was changed from "pending" to "ready", drop the future.
if this.state[i].is_ready() {
// SAFETY: we're done with the future, drop in-place
// SAFETY: the future state has been changed to "ready" which
// means we'll no longer poll the future, so it's safe to drop
unsafe { ManuallyDrop::drop(fut.get_unchecked_mut()) };
}