Struct Promise
pub struct Promise<T>(/* private fields */);
Expand description
Represents the result of a concurrent operation.
This is similar to a std::future::Future
except that it represents an
operation which requires exclusive access to a store in order to make
progress – without monopolizing that store for the lifetime of the
operation.
Implementations§
§impl<T> Promise<T>where
T: 'static,
impl<T> Promise<T>where
T: 'static,
pub fn map<U>(
self,
fun: impl FnOnce(T) -> U + Send + Sync + 'static,
) -> Promise<U>
pub fn map<U>( self, fun: impl FnOnce(T) -> U + Send + Sync + 'static, ) -> Promise<U>
Map the result of this Promise
from one value to another.
pub async fn get<U>(
self,
store: impl AsContextMut<Data = U>,
) -> Result<T, Error>where
U: Send,
pub async fn get<U>(
self,
store: impl AsContextMut<Data = U>,
) -> Result<T, Error>where
U: Send,
Convert this Promise
to a future which may be await
ed for its
result.
The returned future will require exclusive use of the store until it
completes. If you need to await more than one Promise
concurrently,
use PromisesUnordered
.
pub fn into_future(self) -> Pin<Box<dyn Future<Output = T> + Send + Sync>>
pub fn into_future(self) -> Pin<Box<dyn Future<Output = T> + Send + Sync>>
Convert this Promise
to a future which may be await
ed for its
result.
Unlike Self::get
, this does not take a store parameter, meaning
the returned future will not make progress until and unless the event
loop for the store it came from is polled. Thus, this method should
only be used from within host functions and not from top-level embedder
code.
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more