pub struct Channel<T> {
state: Mutex<ChannelState<T>>,
consumer_wait: Condvar,
producer_wait: Condvar,
n_consumers: usize,
}
Expand description
MPMC (Multi Producers Multi Consumers) queue integrated with Worker.
Channel offers Channel::wait_complete() to guarantee all the tasks are executed.
This only exposes methods for producers.
Fields§
§state: Mutex<ChannelState<T>>
§consumer_wait: Condvar
§producer_wait: Condvar
§n_consumers: usize
Implementations§
source§impl<T> Channel<T>
impl<T> Channel<T>
fn new(len: usize, n_consumers: usize) -> Self
fn close(&self)
sourcefn pop(&self) -> Option<T>
fn pop(&self) -> Option<T>
Pops a task from the channel.
If the queue is closed and also empty, this returns None. This returns all the tasks in the queue even while this is closed.
sourcepub fn push(&self, item: T) -> bool
pub fn push(&self, item: T) -> bool
Push a task.
This blocks if the channel is full.
If the channel is closed, this returns false
.
sourcepub fn wait_complete(&self)
pub fn wait_complete(&self)
Wait until all the tasks have been executed.
This guarantees that all the tasks in this channel are not only consumed but also executed.
Auto Trait Implementations§
impl<T> RefUnwindSafe for Channel<T>
impl<T> Send for Channel<T>where
T: Send,
impl<T> Sync for Channel<T>where
T: Send,
impl<T> Unpin for Channel<T>where
T: Unpin,
impl<T> UnwindSafe for Channel<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more