What is async-channel and how does it work?
masterasync-channel is an asynchronous multi-producer multi-consumer (MPMC) channel implementation. In this model, each message sent into the channel is received by exactly one consumer among all active receivers.
There are two types of channels available:
- Bounded channels: Have a fixed, limited capacity.
- Unbounded channels: Have unlimited capacity.
A channel consists of a Sender and a Receiver side. Both sides are Clone, allowing them to be shared across multiple threads or tasks.
Channel Lifecycle and Closing:
- Automatic Closing: A channel closes automatically when either all
Senders are dropped or allReceivers are dropped. - Manual Closing: You can manually close a channel by calling
Sender::close()orReceiver::close(). - Behavior when closed: Once a channel is closed, no new messages can be sent. However, any messages that were already in the channel can still be received by consumers.