pub struct Sender<T> { /* private fields */ }Expand description
Implementations§
Source§impl<T> Sender<T>
impl<T> Sender<T>
Sourcepub async fn send(&self, value: T) -> Result<(), SendError<T>>
pub async fn send(&self, value: T) -> Result<(), SendError<T>>
Sends a value, waiting in line for room if the channel is full.
§Errors
A SendError holding the value when the receiver is closed or gone.
§Cancel safety
A dropped future sent nothing and drops its value; it holds no slot.
use nuclei::sync::local::mpsc;
nuclei::runtime::block_on(async {
let (tx, mut rx) = mpsc::channel(1);
tx.send(1).await.unwrap();
assert_eq!(rx.recv().await, Some(1));
});Sourcepub fn try_send(&self, value: T) -> Result<(), TrySendError<T>>
pub fn try_send(&self, value: T) -> Result<(), TrySendError<T>>
Sends a value at once, or says why it cannot be sent. It never takes a slot ahead of a send or reservation that is waiting.
§Errors
TrySendError::Full if no slot is free or a send is waiting,
TrySendError::Closed if the receiver closed or was dropped. Both
hold the value back.
Sourcepub fn try_reserve(&self) -> Result<Permit<'_, T>, TrySendError<()>>
pub fn try_reserve(&self) -> Result<Permit<'_, T>, TrySendError<()>>
Reserves a slot at once if one is free and nobody waits.
§Errors
TrySendError::Full if no slot is free or a send is waiting,
TrySendError::Closed if the receiver closed or was dropped.
Sourcepub async fn closed(&self)
pub async fn closed(&self)
Completes when the receiver has been closed or dropped. Cancel safe; once the channel is closed every call completes at once.
Sourcepub fn same_channel(&self, other: &Self) -> bool
pub fn same_channel(&self, other: &Self) -> bool
Whether both senders send to the same channel.
Sourcepub fn max_capacity(&self) -> usize
pub fn max_capacity(&self) -> usize
The channel’s maximum capacity: the buffer it was created with.