priority-scheduler-queue
    Preparing search index...

    Class PriorityQueueFifo

    A priority-first FIFO async scheduler with bounded concurrency.

    Higher priority buckets are drained first; within the same priority, jobs execute in FIFO order. Backpressure is applied via maxQueueSize.

    • Priority buckets (higher number → earlier execution)
    • FIFO within each priority
    • Concurrency capped by maxConcurrency
    • Pause/Resume, idle detection, and queue clearing
    const q = new PriorityQueueFifo({ maxConcurrency: 2 });
    q.add(async () => 'low', { priority: 0 });
    q.add(async () => 'high', { priority: 10 });
    await q.onIdle(); // resolves when queue + running are empty
    Index

    Scheduling

    Coordination

    Control

    Metrics

    Constructors

    Scheduling

    • Enqueue a task for execution.

      Type Parameters

      • T

        The resolved value type of the task promise.

      Parameters

      • taskFn: () => Promise<T>

        Async function to execute.

      • taskOptions: { id?: string; priority?: number } = {}

        Optional priority and custom id.

      Returns Promise<T>

      A promise that resolves/rejects with the task result.

      If the queue is full (see SchedulerOptions.maxQueueSize).

      const result = await queue.add(() => fetchJson(url), { priority: 5 });
      

    Coordination

    • Resolves when the queue is completely idle: no running tasks, no pending starters, no queued items.

      Returns Promise<void>

    Control

    • Reject and remove all queued (not-yet-started) jobs. Running jobs are unaffected.

      Parameters

      • OptionalfinalError: unknown

        Optional reason; defaults to a generic cancellation Error.

      Returns void

    • Temporarily stop starting new tasks. Running tasks continue.

      Returns void

    • Resume starting tasks if previously paused.

      Returns void

    Metrics

    • get isCurrentlyPaused(): boolean

      Whether the scheduler is currently paused.

      Returns boolean

    • get runningCount(): number

      Number of running tasks + pending starters (<= maxConcurrency).

      Returns number

    • get size(): number

      Current number of enqueued items (not counting in-flight starters).

      Returns number

    Constructors