Struct command_executor::blocking_queue::BlockingQueue
source · pub struct BlockingQueue<E, S>where
E: Send + Sync,
S: Send + Sync + Clone,{ /* private fields */ }
Expand description
Blocking bounded queue
E: Send + Sync
- the element type
S: Send + Sync + Clone
- the signal type. Signals can be used to provide out of band
communication between threads
This is a multiple producers / multiple consumers blocking bounded queue.
Reference: Producer-Consumer
Implementations§
source§impl<E, S> BlockingQueue<E, S>where
E: Send + Sync,
S: Send + Sync + Clone,
impl<E, S> BlockingQueue<E, S>where E: Send + Sync, S: Send + Sync + Clone,
sourcepub fn new(size: usize) -> BlockingQueue<E, S>
pub fn new(size: usize) -> BlockingQueue<E, S>
Create a new queue with size
capacity
use command_executor::blocking_queue::BlockingQueue;
let q: BlockingQueue<i32, i32> = BlockingQueue::new(4);
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The current length of the queue
use command_executor::blocking_queue::BlockingQueue;
let q: BlockingQueue<i32, i32> = BlockingQueue::new(4);
q.enqueue(11);
assert_eq!(q.len(), 1);
sourcepub fn wait_empty(&self, timeout: Duration) -> bool
pub fn wait_empty(&self, timeout: Duration) -> bool
Wait until the queue is empty.
Note that the empty state is temporary. This method is mostly useful when we know that no elements are to be enqueued and we what an indication of completion.
sourcepub fn enqueue(&self, element: E)
pub fn enqueue(&self, element: E)
Enqueue an element. When the queue is full will block until space available.
sourcepub fn try_enqueue(&self, element: E, timeout: Duration) -> Option<E>
pub fn try_enqueue(&self, element: E, timeout: Duration) -> Option<E>
Enqueue an element with timeout. When timeout is exceeded return the element to caller.
sourcepub fn dequeue(&self) -> (Option<E>, Option<S>)
pub fn dequeue(&self) -> (Option<E>, Option<S>)
Dequeue an element or a signal from the queue. When the queue is empty will block until an element or a signal are available
sourcepub fn try_dequeue(&self, timeout: Duration) -> (Option<E>, Option<S>)
pub fn try_dequeue(&self, timeout: Duration) -> (Option<E>, Option<S>)
Dequeue and element or a signal from the queue with timeout.
sourcepub fn signal(&self, signal: S)
pub fn signal(&self, signal: S)
Deliver a signal to Queue consumers.
Note that the signal is visible to all consumers until cleared
sourcepub fn clear_signal(&self)
pub fn clear_signal(&self)
Clear the signal. Usually it is better if consumers ignore signals they already processed.