Function futures::future::lazy [] [src]

pub fn lazy<R, F>(f: F) -> Lazy<R, F> where
    F: FnOnce(&mut Context) -> R,
    R: IntoFuture

Creates a new future which will eventually be the same as the one created by the closure provided.

The provided closure is only run once the future is polled. Once run, however, this future is the same as the one the closure creates.

Examples

use futures::prelude::*;
use futures::future::{self, FutureResult};

let a = future::lazy(|_| future::ok::<u32, u32>(1));

let b = future::lazy(|_| -> FutureResult<u32, u32> {
    panic!("oh no!")
});
drop(b); // closure is never run