Struct pawawwewism::PromiseHandle
source · 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>
impl<T> PromiseHandle<T>
sourcepub fn block(self) -> Result<T, PromiseDropped>
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.
sourcepub async fn wait(self) -> Result<T, PromiseDropped>
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.
sourcepub fn will_block(&self) -> bool
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.