Struct Promise

Source
pub struct Promise<T> { /* private fields */ }
Expand description

The sending side of a promise which can be used to complete a future. If 2 promises are of the same type, they can be merged and then all the futures will be resolved with clones of the result.

Implementations§

Source§

impl<T> Promise<T>

Source

pub fn new() -> (Promise<T>, PromiseFuture<T>)

Create the sending and receiving parts of the promise.

Source

pub fn fulfill_unmergable(self, result: T)

Fulfill the promise, the future will be woken and can retrieve the result, if used on a merged Promise the merged futures will receive PromiseDropped. So prefer Promise::fulfill on mergable results.

Source§

impl<T: Clone> Promise<T>

Source

pub fn fulfill(self, result: T)

Fulfill the promise, the future will be woken and can retrieve the result. Any merged Promises will be fulfilled at the same time

Source

pub fn merge(&mut self, other: Self)

Merge another promise of the same type into this promise, the future paired with the other promise will be linked to this and will be completed when this one is fulfilled or dropped.

Trait Implementations§

Source§

impl<T> Drop for Promise<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.