pub struct FutureReader<T> { /* private fields */ }
runtime
and component-model
and component-model-async
only.Expand description
Represents the readable end of a Component Model future
.
Note that FutureReader
instances must be disposed of using either read
or close
; otherwise the in-store representation will leak and the writer
end will hang indefinitely. Consider using GuardedFutureReader
to
ensure that disposal happens automatically.
Implementations§
Source§impl<T> FutureReader<T>
impl<T> FutureReader<T>
Sourcepub async fn read(self, accessor: impl AsAccessor) -> Option<T>
pub async fn read(self, accessor: impl AsAccessor) -> Option<T>
Read the value from this future
.
The returned Future
will yield Err
if the guest has trapped
before it could produce a result.
The [Accessor
] provided can be acquired from Instance::run_concurrent
or
from within a host function for example.
§Panics
Panics if the store that the [Accessor
] is derived from does not own
this future.
Sourcepub async fn watch_writer(&mut self, accessor: impl AsAccessor)
pub async fn watch_writer(&mut self, accessor: impl AsAccessor)
Wait for the write end of this future
to be dropped.
The [Accessor
] provided can be acquired from
Instance::run_concurrent
or from within a host function for example.
§Panics
Panics if the store that the [Accessor
] is derived from does not own
this future.
Sourcepub fn from_val(
store: impl AsContextMut<Data: Send>,
instance: Instance,
value: &Val,
) -> Result<Self>
pub fn from_val( store: impl AsContextMut<Data: Send>, instance: Instance, value: &Val, ) -> Result<Self>
Attempt to convert the specified Val
to a FutureReader
.
Sourcepub fn close(&mut self, store: impl AsContextMut)
pub fn close(&mut self, store: impl AsContextMut)
Close this FutureReader
, writing the default value.
§Panics
Panics if the store that the [Accessor
] is derived from does not own
this future. Usage of this future after calling close
will also cause
a panic.
Sourcepub fn close_with(&mut self, accessor: impl AsAccessor)
pub fn close_with(&mut self, accessor: impl AsAccessor)
Convenience method around Self::close
.
Sourcepub fn guard<A>(self, accessor: A) -> GuardedFutureReader<T, A>where
A: AsAccessor,
pub fn guard<A>(self, accessor: A) -> GuardedFutureReader<T, A>where
A: AsAccessor,
Returns a GuardedFutureReader
which will auto-close this future on
drop and clean it up from the store.
Note that the accessor
provided must own this future and is
additionally transferred to the GuardedFutureReader
return value.
Trait Implementations§
Source§impl<T> Debug for FutureReader<T>
impl<T> Debug for FutureReader<T>
Source§impl<T, A> From<GuardedFutureReader<T, A>> for FutureReader<T>where
A: AsAccessor,
impl<T, A> From<GuardedFutureReader<T, A>> for FutureReader<T>where
A: AsAccessor,
Source§fn from(guard: GuardedFutureReader<T, A>) -> Self
fn from(guard: GuardedFutureReader<T, A>) -> Self
impl<T: Send + Sync> ComponentType for FutureReader<T>
impl<T: Send + Sync> Lift for FutureReader<T>
impl<T: Send + Sync> Lower for FutureReader<T>
Auto Trait Implementations§
impl<T> Freeze for FutureReader<T>
impl<T> RefUnwindSafe for FutureReader<T>where
T: RefUnwindSafe,
impl<T> Send for FutureReader<T>where
T: Send,
impl<T> Sync for FutureReader<T>where
T: Sync,
impl<T> Unpin for FutureReader<T>where
T: Unpin,
impl<T> UnwindSafe for FutureReader<T>where
T: UnwindSafe,
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