Struct promising_future::Promise
[−]
[src]
pub struct Promise<T>(_);
A box for resolving a Future
.
A Promise
is a write-once box which corresponds with a Future
and may be used to resolve it.
A Promise
is initially pending, and is completed once it is consumed, either by its set
method, or by going out of scope. The former is "fulfilling" the Promise
; the latter is
leaving it "unfulfilled".
It may only be created in a pair with a Future
using the function future_promise()
.
Methods
impl<T> Promise<T>
fn set(self, v: T)
Fulfill the Promise
by resolving the corresponding Future
with a value.
fn canceled(&self) -> bool
Return true if the corresponding Future
no longer exists, and so any value set would be
discarded.
let (fut, prom) = future_promise(); thread::spawn(move || { let mut s = State::new(); while !prom.canceled() { match s.perform_action() { None => (), Some(res) => { prom.set(res); break }, } } }); // ... mem::drop(fut);