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,

source

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);
source

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);
source

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.

source

pub fn enqueue(&self, element: E)

Enqueue an element. When the queue is full will block until space available.

source

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.

source

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

source

pub fn try_dequeue(&self, timeout: Duration) -> (Option<E>, Option<S>)

Dequeue and element or a signal from the queue with timeout.

source

pub fn signal(&self, signal: S)

Deliver a signal to Queue consumers.

Note that the signal is visible to all consumers until cleared

source

pub fn clear_signal(&self)

Clear the signal. Usually it is better if consumers ignore signals they already processed.

Auto Trait Implementations§

§

impl<E, S> RefUnwindSafe for BlockingQueue<E, S>

§

impl<E, S> Send for BlockingQueue<E, S>

§

impl<E, S> Sync for BlockingQueue<E, S>

§

impl<E, S> Unpin for BlockingQueue<E, S>

§

impl<E, S> UnwindSafe for BlockingQueue<E, S>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.