clean-jsdoc-theme API

Queue

Extends: EventEmitter

Source: queue.js:61

An ordered, event-driven task runner.

Queue extends Node's EventEmitter, so the inheritance chain and the emitted events both show up in the generated page.

Tasks pushed after Queue#clear runs are rejected — clearing aborts the in-flight signal.

Fires

  • Queue#event:drain
  • Queue#event:error

Listens

  • module:forge/cache.Cache#event:evict

Example

Draining a queue

CODE
const q = new Queue({ concurrency: 2 });
q.on('drain', () => console.log('done'));
q.push({ id: 't1', run: async () => doWork() });
await q.drain();
  • Since: 1.1.0
  • Version: 1.3.0
  • Copyright: 2024 The clean-jsdoc-theme team
  • Author: The clean-jsdoc-theme team
  • Requires: module:forge/cache
  • TODO:
    • Add backpressure when the pending list exceeds a high-water mark.

Constructor

new Queue([options])

Parameters

  • options (Object, optional, default: "{}") — Queue configuration.
    • options.concurrency (number, optional, default: 1) — How many tasks run at once (clamped to MAX_CONCURRENCY).
    • options.autoStart (boolean, optional, default: true) — Start draining as soon as a task is pushed.

Instance Methods

push(task) -> this

Add a task to the queue, inserted by Priority.

Parameters

  • task (Task) — The task to enqueue.

Returns

  • this — The queue, for chaining.

drain() -> Promise.<number>

Run every pending task and resolve once the queue is empty.

Returns

  • Promise.<number> — The number of tasks that ran.

Fires

  • Queue#event:drain

Example

drain.js
const ran = await queue.drain();

tasks()

generator
queue.js:127

Iterate pending tasks in scheduling order, highest priority first.

Yields

  • Task — The next pending task.

Example

The @lang directive forces this block's language

CODE
for (const task of queue.tasks()) {
  console.log(task.id satisfies string);
}

onError(error) -> void

abstract
queue.js:138

Handle a task failure. Subclasses must implement this.

Parameters

  • error (Error) — The error a task threw.

Returns

  • void

_next() -> Task | undefined

protected
queue.js:148

Pull and start the next task. Internal scheduling step.

Returns

  • Task | undefined — The task that was started, if any.

clear() -> void

Stop and clear the queue, aborting any in-flight task.

Returns

  • void

Instance Fields

concurrency

readonly
queue.js:76

Effective concurrency, clamped to MAX_CONCURRENCY.

Type

number