pub struct TaskQueueManager { /* private fields */ }Expand description
Manages multiple TaskQueues and picks by priority.
Like Chrome’s base::sequence_manager::SequenceManager — maintains one
TaskQueue per priority level and picks from the highest non-empty
enabled queue each iteration.
§Delayed tasks
Tasks with a future run_at go into a BinaryHeap (min-heap sorted
by deadline). promote_delayed() pops only
ready tasks — O(k log n) where k = newly ready tasks. With 1000 timers
and 0 ready, promotion is O(1) (peek at heap top).
§Anti-starvation
After STARVATION_THRESHOLD consecutive picks from high-priority
queues (Input, UserBlocking), forces one pick from the lowest non-empty
queue. Counter resets whether the forced pick succeeds or not.
Implementations§
Source§impl TaskQueueManager
impl TaskQueueManager
Sourcepub fn push(&mut self, task: Task)
pub fn push(&mut self, task: Task)
Post a task to the appropriate priority queue.
If the task has a future run_at, it goes to the delayed min-heap.
Otherwise it goes directly into the priority queue.
Sourcepub fn pick(&mut self) -> Option<Task>
pub fn pick(&mut self) -> Option<Task>
Pick the highest-priority ready task.
Returns None if all queues are empty or disabled.
Applies anti-starvation after consecutive high-priority picks.
Sourcepub fn promote_delayed(&mut self)
pub fn promote_delayed(&mut self)
Move delayed tasks that are now ready into their priority queues.
Uses a min-heap: peeks at the earliest deadline, pops if ready. O(k log n) where k = tasks becoming ready. When no tasks are ready (the common case), this is O(1) — just one peek.
Sourcepub fn next_delayed_ready_in(&self) -> Option<Duration>
pub fn next_delayed_ready_in(&self) -> Option<Duration>
Time until the next delayed task is ready.
Returns None if there are no delayed tasks.
O(1) — just peeks at the heap top.
Sourcepub fn queue(&self, priority: TaskPriority) -> &TaskQueue
pub fn queue(&self, priority: TaskPriority) -> &TaskQueue
Get a reference to a specific priority queue.
Sourcepub fn queue_mut(&mut self, priority: TaskPriority) -> &mut TaskQueue
pub fn queue_mut(&mut self, priority: TaskPriority) -> &mut TaskQueue
Get a mutable reference to a specific priority queue.
Use for per-queue operations like enable/disable:
manager.queue_mut(TaskPriority::Timer).set_enabled(false);Sourcepub fn ready_count(&self) -> usize
pub fn ready_count(&self) -> usize
Total tasks across all queues that are actually pickable (in enabled queues).
Sourcepub fn delayed_count(&self) -> usize
pub fn delayed_count(&self) -> usize
Number of delayed tasks waiting for their deadline.
Sourcepub fn has_delayed(&self) -> bool
pub fn has_delayed(&self) -> bool
Whether there are delayed tasks pending (for park timeout calculation).