pub struct SenderRef<'a, T> { /* private fields */ }
Expand description
A borrowing handle for sending elements through a bounded split Channel
.
Implementations§
Source§impl<T> SenderRef<'_, T>
impl<T> SenderRef<'_, T>
Sourcepub fn max_capacity(&self) -> usize
pub fn max_capacity(&self) -> usize
Returns the maximum buffer capacity of the channel.
This is the capacity initially specified when creating the channel and remains constant.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the current capacity of the channel.
The capacity goes down when sending a value and goes up when receiving a value. When the capacity is zero, any subsequent sends will only resolve once sufficient capacity is available
Sourcepub fn same_channel(&self, other: &Self) -> bool
pub fn same_channel(&self, other: &Self) -> bool
Returns true
if self
and other
are handles for the same channel
instance.
Sourcepub fn try_send(&self, elem: T) -> Result<(), TrySendError<T>>
pub fn try_send(&self, elem: T) -> Result<(), TrySendError<T>>
Sends a value through the channel if there is sufficient capacity.
§Errors
Fails, if the queue is closed or there is no available capacity.
Sourcepub async fn send(&self, elem: T) -> Result<(), SendError<T>>
pub async fn send(&self, elem: T) -> Result<(), SendError<T>>
Sends a value through the channel, potentially blocking until there is sufficient capacity.
§Errors
Fails, if the queue is closed.
Sourcepub fn try_reserve(&self) -> Result<Permit<'_, T>, TrySendError<()>>
pub fn try_reserve(&self) -> Result<Permit<'_, T>, TrySendError<()>>
Attempts to reserve a slot in the channel without blocking, if none are available.
The returned Permit
can be used to immediately send a value to the
channel at a later point.
Dropping the permit without sending a value will return the capacity to
the channel.
§Errors
Fails, if there are no available permits or the channel has been closed.
§Examples
use async_unsync::bounded;
let mut chan = bounded::channel(1);
let (tx, mut rx) = chan.split();
// reserve capacity, reducing available slots to 0
let permit = tx.try_reserve().unwrap();
assert!(tx.try_send(1).is_err());
assert!(tx.try_reserve().is_err());
permit.send(1);
assert_eq!(rx.recv().await, Some(1));
Sourcepub async fn reserve(&self) -> Result<Permit<'_, T>, SendError<()>>
pub async fn reserve(&self) -> Result<Permit<'_, T>, SendError<()>>
Attempts to reserve a slot in the channel without blocking.
If no capacity is available in the channel, this will block until a slot
becomes available.
The returned Permit
can be used to immediately send a value to the
channel at a later point.
Dropping the permit without sending a value will return the capacity to
the channel.
§Errors
Fails, if there are no available permits or the channel has been closed.
§Examples
use async_unsync::bounded;
let mut chan = bounded::channel(1);
let (tx, mut rx) = chan.split();
// reserve capacity, reducing available slots to 0
let permit = tx.reserve().await.unwrap();
assert!(tx.try_send(1).is_err());
assert!(tx.try_reserve().is_err());
permit.send(1);
assert_eq!(rx.recv().await, Some(1));