pub struct Queue<T> { /* private fields */ }Expand description
Queue that is limited in size and supports resizing.
This queue implementation has the following characteristics:
- Resizable (
deadqueue::resizable::Queue) - Based on
deadqueue::unlimited::Queue - Has limited capacity with back pressure on push
- Supports resizing
- Enabled via the
resizablefeature in yourCargo.toml
Implementations§
Source§impl<T> Queue<T>
impl<T> Queue<T>
Sourcepub async fn pop(&self) -> T
pub async fn pop(&self) -> T
Get an item from the queue. If the queue is currently empty this method blocks until an item is available.
Sourcepub fn try_pop(&self) -> Option<T>
pub fn try_pop(&self) -> Option<T>
Try to get an item from the queue. If the queue is currently empty return None instead.
Sourcepub fn try_push(&self, item: T) -> Result<(), T>
pub fn try_push(&self, item: T) -> Result<(), T>
Try to push an item to the queue. If the queue is currently
full return the object as Err<T>.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Get capacity of the queue (maximum number of items queue can store).
Sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Returns true if the queue is full.
Note: this can give an incorrect result if a simultaneous push/pop
and resize ocurr while this function is executing. try_push() is the
reccomended and safer mechanism in most circumstances. This method
is provided as a convenience API.
Sourcepub fn available(&self) -> isize
pub fn available(&self) -> isize
The number of available items in the queue. If there are no items in the queue this number can become negative and stores the number of futures waiting for an item.
Sourcepub fn subscribe_full(&self) -> Receiver
pub fn subscribe_full(&self) -> Receiver
Get a Receiver object that can repeatedly be awaited for
queue-full notifications.
Sourcepub async fn wait_empty(&self)
pub async fn wait_empty(&self)
Await until the queue is empty.
Sourcepub fn subscribe_empty(&self) -> Receiver
pub fn subscribe_empty(&self) -> Receiver
Get a Receiver object that can repeatedly be awaited for
queue-empty notifications.
Sourcepub async fn resize(&self, target_capacity: usize)
pub async fn resize(&self, target_capacity: usize)
Resize queue. This increases or decreases the queue capacity accordingly.
Note: Increasing the capacity of a queue happens without blocking unless a resize operation is already in progress. Decreasing the capacity can block if there are futures waiting to push items to the queue.