diff --git a/tokio/src/stream/iter.rs b/tokio/src/stream/iter.rs index 5909b4cf4..36eeb5612 100644 --- a/tokio/src/stream/iter.rs +++ b/tokio/src/stream/iter.rs @@ -44,7 +44,8 @@ where { type Item = I::Item; - fn poll_next(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + ready!(crate::coop::poll_proceed(cx)); Poll::Ready(self.iter.next()) } diff --git a/tokio/tests/stream_iter.rs b/tokio/tests/stream_iter.rs new file mode 100644 index 000000000..45148a7a8 --- /dev/null +++ b/tokio/tests/stream_iter.rs @@ -0,0 +1,18 @@ +use tokio::stream; +use tokio_test::task; + +use std::iter; + +#[tokio::test] +async fn coop() { + let mut stream = task::spawn(stream::iter(iter::repeat(1))); + + for _ in 0..10_000 { + if stream.poll_next().is_pending() { + assert!(stream.is_woken()); + return; + } + } + + panic!("did not yield"); +}