Function futures::stream::poll_fn[][src]

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

Creates a new stream wrapping around a function returning Poll.

Polling the returned stream delegates to the wrapped function.

Examples

use futures::prelude::*;
use futures::stream::poll_fn;

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()))
});