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<R>(
self,
batch_limit: usize,
f: impl AsyncFnOnce(&mut BatchSender<T>) -> Result<R, SendError<()>>,
) -> Result<R, SendError<()>>
pub async fn autobatch<R>( self, batch_limit: usize, f: impl AsyncFnOnce(&mut BatchSender<T>) -> Result<R, SendError<()>>, ) -> Result<R, SendError<()>>
Automatically accumulate sends into a buffer of size batch_limit
and send when full.
Sourcepub async fn autobatch_or_cancel(
self,
capacity: usize,
f: impl AsyncFnOnce(&mut BatchSender<T>) -> Result<(), SendError<()>>,
)
pub async fn autobatch_or_cancel( self, capacity: usize, f: impl AsyncFnOnce(&mut BatchSender<T>) -> Result<(), SendError<()>>, )
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.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Sender<T>
impl<T> RefUnwindSafe for Sender<T>
impl<T> Send for Sender<T>where
T: Send,
impl<T> Sync for Sender<T>where
T: Send,
impl<T> !Unpin for Sender<T>
impl<T> UnwindSafe for Sender<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
Mutably borrows from an owned value. Read more