Function futures::promise [] [src]

pub fn promise<T>() -> (Complete<T>, Promise<T>) where T: Send + 'static

Creates a new in-memory promise used to represent completing a computation.

A promise in this library is a concrete implementation of the Future trait used to complete a computation from one location with a future representing what to do in another.

This function is similar to Rust's channels found in the standard library. Two halves are returned, the first of which is a Promise which implements the Future trait. The second half is a Complete handle which is used to signal the end of a computation.

Each half can be separately owned and sent across threads.

Examples

use futures::*;

let (c, p) = promise::<i32>();

p.map(|i| {
    println!("got: {}", i);
}).forget();

c.complete(3);