Function cosmic::iced_futures::futures::prelude::stream::poll_immediate
source · pub fn poll_immediate<S>(s: S) -> PollImmediate<S>where
S: Stream,
Expand description
Creates a new stream that always immediately returns Poll::Ready when awaiting it.
This is useful when immediacy is more important than waiting for the next item to be ready.
§Examples
use futures::stream::{self, StreamExt};
use futures::task::Poll;
let mut r = stream::poll_immediate(Box::pin(stream::iter(1_u32..3)));
assert_eq!(r.next().await, Some(Poll::Ready(1)));
assert_eq!(r.next().await, Some(Poll::Ready(2)));
assert_eq!(r.next().await, None);
let mut p = stream::poll_immediate(Box::pin(stream::once(async {
futures::pending!();
42_u8
})));
assert_eq!(p.next().await, Some(Poll::Pending));
assert_eq!(p.next().await, Some(Poll::Ready(42)));
assert_eq!(p.next().await, None);