Struct PriorityQueue

Source
pub struct PriorityQueue<M, P>
where M: Send, P: PartialOrd + Ord,
{ /* private fields */ }
Expand description

A queue which orders messages by priority

Implementations§

Source§

impl<M, P> PriorityQueue<M, P>
where M: Send, P: PartialOrd + Ord,

Source

pub fn new() -> PriorityQueue<M, P>

Create a new PriorityQueue

Source

pub fn sync(&self, stash: &mut Stash<'_, M, P>)

Inserts all elements from the stash to the PriorityQueue, empties stash. This function waits until the on the queue is locked.

Source

pub fn send(&self, message: M, prio: P, stash: &mut Stash<'_, M, P>)

Pushes an message with prio onto the queue, uses a Stash as temporary storage when the queue is contended. Drains the stash in the uncontended case. This function does not wait for the lock on the queue.

Source

pub fn send_sync(&self, message: M, prio: P, stash: &mut Stash<'_, M, P>)

Pushes a message with prio onto the queue, drains the Stash first. This function waits until the on the queue is locked.

Source

pub fn send_stashed(&self, message: M, prio: P, stash: &mut Stash<'_, M, P>)

Pushes an message to the Stash. will not try to send data to the queue. Use this to combine some messages together before calling sync() to send them. This function does not wait for the lock on the queue.

Source

pub fn send_batched( &self, message: M, prio: P, batch_size: usize, stash: &mut Stash<'_, M, P>, )

Combines the above to collect at least ‘batch_size’ messages in the stash before trying to send them out. Use this to batch some messages together before calling sync() to send them. This function does not wait for the lock on the queue.

Source

pub fn send_nostash(&self, message: M, prio: P)

Pushes a message with prio onto the queue without using a stash. This function waits until the on the queue is locked. No stash involved, this should be not used with threads that have a stash since it won’t get drained first. Can be used to send synchronous out-of-band message bypassing the stash.

Source

pub fn recv_guard(&self) -> ReceiveGuard<'_, M, P>

Returns the smallest message from a queue. This message is wraped in a ReceiveGuard/Message

Source

pub fn try_recv_guard(&self) -> Option<ReceiveGuard<'_, M, P>>

Try to get the smallest message from a queue. Will return Some when a message is available. This will not wait on the queue lock.

Source

pub fn maybe_recv_guard(&self) -> Option<ReceiveGuard<'_, M, P>>

Try to get the smallest message from a queue. Will return Some when a message is available. This will wait on the queue lock but return None when the queue is empty.

Source

pub fn recv(&self) -> Message<M, P>

Returns the smallest message from a queue.

Source

pub fn try_recv(&self) -> Option<Message<M, P>>

Try to get the smallest message from a queue. Will return Some when a message is available. This will not wait on the queue lock.

Source

pub fn maybe_recv(&self) -> Option<Message<M, P>>

Try to get the smallest message from a queue. Will return Some when a message is available. This will wait on the queue lock but return None when the queue is empty.

Source

pub fn in_progress(&self) -> usize

Returns the number of messages in flight. This is the .len() plus any receiver that still holds a guard. Note: Informal only, this method will be racy when other threads modify the PriorityQueue.

Source

pub fn is_empty(&self) -> bool

Returns true when the Stash contains no messages. Note: Informal only, this method will be racy when other threads modify the PriorityQueue.

Source

pub fn len(&self) -> usize

Returns the number of messages in the stash. Note: Informal only, this method will be racy when other threads modify the PriorityQueue.

Source

pub fn reserve(&self, additional: usize)

Reserves capacity for at least additional more elements to be inserted in the PriorityQueue.

Trait Implementations§

Source§

impl<M, P> Debug for PriorityQueue<M, P>
where M: Send + Debug, P: PartialOrd + Ord + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M, P> Default for PriorityQueue<M, P>
where M: Send, P: PartialOrd + Ord,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<M, P> !Freeze for PriorityQueue<M, P>

§

impl<M, P> !RefUnwindSafe for PriorityQueue<M, P>

§

impl<M, P> Send for PriorityQueue<M, P>
where P: Send,

§

impl<M, P> Sync for PriorityQueue<M, P>
where P: Send,

§

impl<M, P> Unpin for PriorityQueue<M, P>
where M: Unpin, P: Unpin,

§

impl<M, P> UnwindSafe for PriorityQueue<M, P>
where M: UnwindSafe, P: 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.