pub struct Promise<T>(/* private fields */);Expand description
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().
Implementations§
Source§impl<T> Promise<T>
impl<T> Promise<T>
Sourcepub fn canceled(&self) -> bool
pub 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);Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Promise<T>
impl<T> RefUnwindSafe for Promise<T>
impl<T> Send for Promise<T>where
T: Send,
impl<T> Sync for Promise<T>where
T: Send,
impl<T> Unpin for Promise<T>
impl<T> UnwindSafe for Promise<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more