Function sync_channel::new_channel
source · pub fn new_channel<T: Send>(minimum_capacity: usize) -> (Sender<T>, Receiver<T>)
Expand description
Create a new channel that allows senders and receivers to asynchronously exchange messages via an internal intermediary buffer.
This channel’s buffer has a bounded capacity of minimum size 2 messages,
and it must be a power of 2 due to the restrictions of the current MPMC queue type that is used.
The given minimum_capacity
will be rounded up to the next largest power of 2, with a minimum value of 2.
When the number of pending (buffered) messages is larger than the capacity,
the channel is considered full.
Depending on whether a non-blocking or blocking send function is invoked,
future attempts to send another message will either block or return a Full
error
until the channel’s buffer is drained by a receiver and space in the buffer becomes available.
For the vast majority of use cases, this function is recommended way to create
a new channel, because there is no need to specify a deadlock prevention method.
To create a channel with different deadlock prevention, see new_channel_with()
.