Function futures::oneshot [] [src]

pub fn oneshot<T>() -> (Complete<T>, Oneshot<T>)

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

A oneshot 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 Complete handle, used to signal the end of a computation and provide its value. The second half is a Oneshot which implements the Future trait, resolving to the value that was given to the Complete handle.

Each half can be separately owned and sent across threads.

Examples

use std::thread;
use futures::*;

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

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

c.complete(3);Run