[][src]Function futures_async_combinators::stream::poll_fn

pub fn poll_fn<T, F>(f: F) -> impl Stream<Item = T> where
    F: FnMut(&mut Context) -> Poll<Option<T>>, 

Creates a new stream wrapping a function returning Poll<Option<T>>.

Polling the returned stream calls the wrapped function.

Examples

use futures_async_combinators::stream::poll_fn;
use core::task::Poll;

let mut counter = 1usize;

let read_stream = poll_fn(move |_| -> Poll<Option<String>> {
    if counter == 0 { return Poll::Ready(None); }
    counter -= 1;
    Poll::Ready(Some("Hello, World!".to_owned()))
});