File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed
futures-util/src/stream/futures_unordered Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -390,6 +390,7 @@ impl<Fut: Future> Stream for FuturesUnordered<Fut> {
390390 // Keep track of how many child futures we have polled,
391391 // in case we want to forcibly yield.
392392 let mut polled = 0 ;
393+ let mut yielded = 0 ;
393394
394395 // Ensure `parent` is correctly set.
395396 self . ready_to_run_queue . waker . register ( cx. waker ( ) ) ;
@@ -519,15 +520,15 @@ impl<Fut: Future> Stream for FuturesUnordered<Fut> {
519520 let task = bomb. task . take ( ) . unwrap ( ) ;
520521 // If the future was awoken during polling, we assume
521522 // the future wanted to explicitly yield.
522- let yielded = task. woken . load ( Relaxed ) ;
523+ yielded + = task. woken . load ( Relaxed ) as usize ;
523524 bomb. queue . link ( task) ;
524525
525526 // If a future yields, we respect it and yield here.
526527 // If all futures have been polled, we also yield here to
527528 // avoid starving other tasks waiting on the executor.
528529 // (polling the same future twice per iteration may cause
529530 // the problem: https://github.com/rust-lang/futures-rs/pull/2333)
530- if yielded || polled == len {
531+ if yielded >= 2 || polled == len {
531532 cx. waker ( ) . wake_by_ref ( ) ;
532533 return Poll :: Pending ;
533534 }
You can’t perform that action at this time.
0 commit comments