Function futures_lite::stream::poll_fn

source ·
pub fn poll_fn<T, F>(f: F) -> PollFn<F>
where F: FnMut(&mut Context<'_>) -> Poll<Option<T>>,
Expand description

Creates a stream from a function returning Poll.

§Examples

use futures_lite::stream::{self, StreamExt};
use std::task::{Context, Poll};

fn f(_: &mut Context<'_>) -> Poll<Option<i32>> {
    Poll::Ready(Some(7))
}

assert_eq!(stream::poll_fn(f).next().await, Some(7));