pub struct Channel<T = ()> {
pub sender: Sender<T>,
pub receiver: Receiver<T>,
}Expand description
Channel struct that combines [async_channel::Sender] and
[async_channel::Receiver] into a single struct with sender
and receiver members representing a single channel.
Fields§
§sender: Sender<T>Sender endpoint of the channel.
receiver: Receiver<T>Receiver endpoint of the channel.
Implementations§
Source§impl<T> Channel<T>
impl<T> Channel<T>
Sourcepub fn bounded(cap: usize) -> Channel<T>
pub fn bounded(cap: usize) -> Channel<T>
Creates a channel with a buffer bounded to cap messages.
Sourcepub fn oneshot() -> Channel<T>
pub fn oneshot() -> Channel<T>
Creates a oneshot channel (a bounded channel with a capacity of one message).
Sourcepub fn drain(&self) -> Result<(), TryRecvError>
pub fn drain(&self) -> Result<(), TryRecvError>
Discards all currently-buffered messages from the channel.
Sourcepub async fn recv(&self) -> Result<T, RecvError>
pub async fn recv(&self) -> Result<T, RecvError>
Receives a message, waiting asynchronously until one is available.
Sourcepub fn try_recv(&self) -> Result<T, TryRecvError>
pub fn try_recv(&self) -> Result<T, TryRecvError>
Attempts to receive a message without blocking, returning an error if the channel is empty.
Sourcepub async fn send(&self, msg: T) -> Result<(), SendError<T>>
pub async fn send(&self, msg: T) -> Result<(), SendError<T>>
Sends a message, waiting asynchronously if the channel is bounded and full.
Sourcepub fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>
pub fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>
Attempts to send a message without blocking, returning an error if the channel is full or closed.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no messages currently buffered in the channel.
Sourcepub fn receiver_count(&self) -> usize
pub fn receiver_count(&self) -> usize
Returns the number of Receiver endpoints currently connected to the channel.
Sourcepub fn sender_count(&self) -> usize
pub fn sender_count(&self) -> usize
Returns the number of Sender endpoints currently connected to the channel.
Sourcepub fn iter(&self) -> ChannelIterator<T> ⓘ
pub fn iter(&self) -> ChannelIterator<T> ⓘ
Returns an iterator that drains all currently-buffered messages from the channel.