pub struct Sender<T> { /* private fields */ }
Expand description
The asynchronous sending half of a channel.
Implementations§
Source§impl<T> Sender<T>
impl<T> Sender<T>
Sourcepub fn into_sync(self) -> SyncSender<T>
pub fn into_sync(self) -> SyncSender<T>
Converts asynchronous Sender
to SyncSender
.
Sourcepub fn send(
&self,
value: T,
) -> impl Future<Output = Result<(), SendError<T>>> + '_
pub fn send( &self, value: T, ) -> impl Future<Output = Result<(), SendError<T>>> + '_
Send a single value.
Returns SendError if all receivers are dropped.
Sourcepub fn send_iter<'a, I>(
&'a self,
values: I,
) -> impl Future<Output = Result<(), SendError<()>>> + 'awhere
I: IntoIterator<Item = T> + 'a,
pub fn send_iter<'a, I>(
&'a self,
values: I,
) -> impl Future<Output = Result<(), SendError<()>>> + 'awhere
I: IntoIterator<Item = T> + 'a,
Send multiple values.
If all receivers are dropped, SendError is returned and unsent values are dropped.
Sourcepub async fn autobatch<F, R>(
self,
batch_limit: usize,
f: F,
) -> Result<R, SendError<()>>
pub async fn autobatch<F, R>( self, batch_limit: usize, f: F, ) -> Result<R, SendError<()>>
Automatically accumulate sends into a buffer of size batch_limit
and send when full.
The callback’s future must be boxed to work around type system limitations in Rust.
There is a git branch that shows what an API based on async closures would look like.
Sourcepub async fn autobatch_or_cancel<F>(self, capacity: usize, f: F)
pub async fn autobatch_or_cancel<F>(self, capacity: usize, f: F)
Same as Sender::autobatch except that it immediately returns
()
when f
returns SendError. This is a convenience
wrapper for the common case that the future is passed to a
spawn function and the receiver being dropped (i.e.
SendError) is considered a clean cancellation.