pub struct Exchanger<T: Send> { /* private fields */ }
Expand description
A thread-safe, shared exchange buffer. Allows multiple producers to push elements in, up to a blocking max capacity. Allows multiple consumers to take elements out, blocking if none available.
Implementations§
Source§impl<T: Send> Exchanger<T>
impl<T: Send> Exchanger<T>
Sourcepub fn new(max_size: usize) -> Self
pub fn new(max_size: usize) -> Self
Creates a new exchanger, that can store at most these elements in the queue.
Note: Putting a value of 0
/zero for max_size implies that this exchanger will do no work
and exchange no items. A recommended minimum value of 1
should be used instead.
Sourcepub fn push(&self, elem: T) -> Result<(), ExchangerError<T>>
pub fn push(&self, elem: T) -> Result<(), ExchangerError<T>>
Push a new element into the exchanger, blocking until space is available.
pub fn try_push(&self, elem: T) -> Result<(), ExchangerError<T>>
Sourcepub fn take(&self) -> Result<T, ExchangerError<T>>
pub fn take(&self) -> Result<T, ExchangerError<T>>
Take a new element from the exchanger, blocking until one is available.
pub fn try_take(&self) -> Result<T, ExchangerError<T>>
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Shuts down this exchanger, preventing new pushes. Any objects already pushed will be
permitted to be taken, and once empty, takers will receive a
TaskError::ExecutorStoppingError