pub struct Promise<T> { /* private fields */ }
Expand description
A container for a value of type T
that may not yet be resolved.
Multiple consumers may obtain the value via shared reference (&
) once resolved.
Implementations§
Source§impl<T> Promise<T>
impl<T> Promise<T>
Sourcepub async fn wait(&self) -> Option<&T>
pub async fn wait(&self) -> Option<&T>
Waits for the promise to be resolved, returning the value once set.
Returns None
if the resolver was dropped before sending a value.
Sourcepub fn try_get(&self) -> Result<&T, PromiseError>
pub fn try_get(&self) -> Result<&T, PromiseError>
Attempts to get the value if it has been resolved, returning an error if not.
Returns PromiseError::Empty
if the value has not yet been set, and PromiseError::Dropped
if the resolver
was dropped before sending a value.
Auto Trait Implementations§
impl<T> Freeze for Promise<T>
impl<T> !RefUnwindSafe for Promise<T>
impl<T> Send for Promise<T>
impl<T> Sync for Promise<T>
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