File tree Expand file tree Collapse file tree 2 files changed +3
-4
lines changed
futures-util/src/stream/futures_unordered Expand file tree Collapse file tree 2 files changed +3
-4
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 }
Original file line number Diff line number Diff line change @@ -268,8 +268,6 @@ fn futures_not_moved_after_poll() {
268268 let fut = future:: ready ( ( ) ) . pending_once ( ) . assert_unmoved ( ) ;
269269 let mut stream = vec ! [ fut; 3 ] . into_iter ( ) . collect :: < FuturesUnordered < _ > > ( ) ;
270270 assert_stream_pending ! ( stream) ;
271- assert_stream_pending ! ( stream) ;
272- assert_stream_pending ! ( stream) ;
273271 assert_stream_next ! ( stream, ( ) ) ;
274272 assert_stream_next ! ( stream, ( ) ) ;
275273 assert_stream_next ! ( stream, ( ) ) ;
You can’t perform that action at this time.
0 commit comments