Skip to main content

TaskQueueManager

Struct TaskQueueManager 

Source
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

Source

pub fn new() -> Self

Create a new set with one empty queue per priority level.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn queue(&self, priority: TaskPriority) -> &TaskQueue

Get a reference to a specific priority queue.

Source

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

pub fn ready_count(&self) -> usize

Total tasks across all queues that are actually pickable (in enabled queues).

Source

pub fn delayed_count(&self) -> usize

Number of delayed tasks waiting for their deadline.

Source

pub fn has_ready(&self) -> bool

Whether there are any pickable tasks in enabled queues.

Source

pub fn is_empty(&self) -> bool

Whether there are no tasks at all (ready or delayed).

Source

pub fn has_delayed(&self) -> bool

Whether there are delayed tasks pending (for park timeout calculation).

Trait Implementations§

Source§

impl Default for TaskQueueManager

Source§

fn default() -> Self

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

Auto Trait Implementations§

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.