pub struct BufferedChannel<T: Send> {
pub chunk_size: usize,
/* private fields */
}Expand description
An asynchronous MPSC channel that buffers messages and reuses allocations with thread locals.
This is a building block for efficient parallel worker tasks.
Cache this channel in a system’s Local to reuse allocated memory.
This is faster than sending each message individually into a channel when communicating between
tasks. Unlike Parallel, this allows you to execute a consuming task while producing tasks are
concurrently sending data into the channel, enabling you to run a serial processing consumer
at the same time as many parallel processing producers.
Fields§
§chunk_size: usizeThe minimum length of a Vec of buffered data before it is sent through the channel.
Implementations§
Source§impl<T: Send> BufferedChannel<T>
impl<T: Send> BufferedChannel<T>
Sourcepub fn unbounded(&self) -> (BufferedReceiver<'_, T>, BufferedSender<'_, T>)
pub fn unbounded(&self) -> (BufferedReceiver<'_, T>, BufferedSender<'_, T>)
Create an unbounded channel and return the receiver and sender.
The created channel can hold an unlimited number of messages.
Sourcepub fn bounded(
&self,
cap: usize,
) -> (BufferedReceiver<'_, T>, BufferedSender<'_, T>)
pub fn bounded( &self, cap: usize, ) -> (BufferedReceiver<'_, T>, BufferedSender<'_, T>)
Create a bounded channel and return the receiver and sender.
The created channel has space to hold at most cap messages at a time.
§Panics
Capacity must be a positive number. If cap is zero, this function will panic.