Skip to main content

BufferedChannel

Struct BufferedChannel 

Source
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: usize

The minimum length of a Vec of buffered data before it is sent through the channel.

Implementations§

Source§

impl<T: Send> BufferedChannel<T>

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: Send> Default for BufferedChannel<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for BufferedChannel<T>

§

impl<T> RefUnwindSafe for BufferedChannel<T>

§

impl<T> Send for BufferedChannel<T>

§

impl<T> Sync for BufferedChannel<T>

§

impl<T> Unpin for BufferedChannel<T>

§

impl<T> UnsafeUnpin for BufferedChannel<T>

§

impl<T> UnwindSafe for BufferedChannel<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.