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

A handle connected to a Promise that will eventually resolve to a value of type T.

A connected pair of Promise and PromiseHandle can be created by calling promise.

Implementations§

source§

impl<T> PromiseHandle<T>

source

pub fn block(self) -> Result<T, PromiseDropped>

Blocks the calling thread until the connected Promise is fulfilled.

If the Promise is dropped without being fulfilled, a PromiseDropped error is returned instead. This typically means one of two things:

  • The thread holding the promise has deliberately decided not to fulfill it (for example, because it has skipped processing an item).
  • The thread holding the promise has panicked.

Usually, the correct way to handle this is to just skip the item expected from the Promise. If the thread has panicked, and it’s a Worker thread, then the next attempt to send a message to it will propagate the panic to the owning thread, and tear down the process as usual.

source

pub async fn wait(self) -> Result<T, PromiseDropped>

Asynchronously waits for the connected Promise to be fulfilled.

Cancellation

This method is cancellation-safe, but it takes self by value, so the value of the Promise will be lost when the resulting Future is cancelled.

source

pub fn will_block(&self) -> bool

Tests whether a call to PromiseHandle::block will block or return immediately.

If this returns false, the connected Promise has been resolved and calling PromiseHandle::block on self will return immediately, without blocking.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for PromiseHandle<T>

§

impl<T> Send for PromiseHandle<T>where T: Send,

§

impl<T> Sync for PromiseHandle<T>where T: Send,

§

impl<T> Unpin for PromiseHandle<T>

§

impl<T> UnwindSafe for PromiseHandle<T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.