pub struct FutureWriter<T: 'static> { /* private fields */ }
Expand description
Represents the writable end of a Component Model future
.
A FutureWriter
can be used to send a single value of T
to the other
end of a future
. In a sense this is similar to a oneshot channel in Rust.
Implementations§
Source§impl<T> FutureWriter<T>
impl<T> FutureWriter<T>
Sourcepub fn write(self, value: T) -> FutureWrite<T> ⓘ
pub fn write(self, value: T) -> FutureWrite<T> ⓘ
Write the specified value
to this future
.
This method is equivalent to an async fn
which sends the value
into
this future. The asynchronous operation acts as a rendezvous where the
operation does not complete until the other side has successfully
received the value.
§Return Value
The returned FutureWrite
is a future that can be .await
’d. The
return value of this future is:
Ok(())
- thevalue
was sent and received. Theself
value was consumed along the way and will no longer be accessible.Err(FutureWriteError { value })
- an attempt was made to sendvalue
but the other half of thisFutureWriter
was dropped before the value was received. This consumesself
because the channel is now dropped, butvalue
is returned in case the caller wants to reuse it.
§Cancellation
The returned future can be cancelled normally via drop
which means
that the value
provided here, along with this FutureWriter
itself,
will be lost. There is also FutureWrite::cancel
which can be used to
possibly re-acquire value
and self
if the operation was cancelled.
In such a situation the operation can be retried at a future date.