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 Oneshot
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 std::thread; use futures::*; let (c, p) = oneshot::<i32>(); thread::spawn(|| { p.map(|i| { println!("got: {}", i); }).wait(); }); c.complete(3);Run