pub struct WorkQueue { /* private fields */ }Expand description
Work queue for deferred tasks.
Thread-safe, FIFO queue with bounded capacity. When the queue is full, new tasks are dropped and the overflow counter is incremented.
§Thread Safety
The queue uses a Mutex<VecDeque<Task>> internally, making it safe
to push from multiple threads. However, heavy contention should be
avoided for performance.
Implementations§
Source§impl WorkQueue
impl WorkQueue
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a work queue with specified capacity.
Capacity is clamped to MAX_CAPACITY.
Sourcepub fn push(&self, task: Task) -> bool
pub fn push(&self, task: Task) -> bool
Push a task to the queue.
Returns true if the task was queued, false if dropped due to overflow.
This is non-blocking - overflow tasks are immediately dropped.
Sourcepub fn try_pop(&self) -> Option<Task>
pub fn try_pop(&self) -> Option<Task>
Try to pop a task from the queue.
Returns None if the queue is empty.
Sourcepub fn drain(&self) -> Vec<Task>
pub fn drain(&self) -> Vec<Task>
Drain all tasks from the queue.
Returns all pending tasks, leaving the queue empty.
Sourcepub fn process_pending(&self, limit: usize) -> usize
pub fn process_pending(&self, limit: usize) -> usize
Process up to limit pending tasks.
Pops and executes tasks in order. Returns the number of tasks successfully executed. Tasks that fail or panic are counted but not returned.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the number of pending tasks.
Note: This is a snapshot and may change immediately after returning.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the queue is empty.
Note: This is a snapshot and may change immediately after returning.
Sourcepub fn dropped_count(&self) -> usize
pub fn dropped_count(&self) -> usize
Get the number of dropped tasks (overflow).
This count accumulates over the lifetime of the queue.