pub struct Promise<T>(/* private fields */);runtime and component-model and component-model-async only.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§
Source§impl<T: 'static> Promise<T>
impl<T: 'static> Promise<T>
Sourcepub 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.
Sourcepub async fn get<U: Send>(self, store: impl AsContextMut<Data = U>) -> Result<T>
pub async fn get<U: Send>(self, store: impl AsContextMut<Data = U>) -> Result<T>
Convert this Promise to a future which may be awaited 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.
Sourcepub fn into_future(
self,
) -> Pin<Box<dyn Future<Output = T> + Send + Sync + 'static>>
pub fn into_future( self, ) -> Pin<Box<dyn Future<Output = T> + Send + Sync + 'static>>
Convert this Promise to a future which may be awaited 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> 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