Skip to content

Commit

Permalink
Revert "Optimize poll loop slightly"
Browse files Browse the repository at this point in the history
This reverts commit ad76225.
  • Loading branch information
richarddd committed Oct 6, 2023
1 parent fb7d128 commit cd4f684
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions core/src/runtime/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,21 @@ impl<'a, 'js> Future for SpawnFuture<'a, 'js> {
return Poll::Ready(false);
}

let mut did_complete = false;
self.0.futures.retain_mut(|f| {
let ready = f.as_mut().poll(cx).is_ready();
did_complete = did_complete || ready;
!ready
});

if did_complete {
let mut completed_indices = Vec::new();

// Iterate over the futures and check their completion status.
for (i, f) in self.0.futures.iter_mut().enumerate() {
if let Poll::Ready(_) = f.as_mut().poll(cx) {
completed_indices.push(i);
}
}

// Remove the completed futures in reverse order to avoid index shifting.
for &idx in completed_indices.iter().rev() {
self.0.futures.remove(idx);
}

if !completed_indices.is_empty() {
Poll::Ready(true)
} else {
Poll::Pending
Expand Down

0 comments on commit cd4f684

Please sign in to comment.