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

pub fn lazy<F, R>(f: F) -> Lazy<F, R> where F: FnOnce() -> 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 has a callback scheduled on it, otherwise the callback never runs. Once run, however, this future is the same as the one the closure creates.

Examples

use futures::future::*;

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

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