Class PriorityQueue<JobReturnType, JobOptions>

Heavily influence by p-queue with the following differences:

  1. Items remain at the head of the queue while they are running so queue.size includes queue.pending items - this is so interested parties can join the results of a queue item while it is running
  2. The options for a job are stored separately to the job in order for them to be modified while they are still in the queue

Type Parameters

Hierarchy (view full)

Constructors

Properties

#private: any
concurrency: number
maxSize: number

Accessors

Methods

  • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

    MDN Reference

    Parameters

    Returns boolean

  • Parameters

    • type: string

    Returns number

  • The difference with .onEmpty is that .onIdle guarantees that all work from the queue has finished. .onEmpty merely signals that the queue is empty, but it could mean that some promises haven't completed yet.

    Parameters

    Returns Promise<void>

    A promise that settles when the queue becomes empty, and all promises have completed; queue.size === 0 && queue.pending === 0.

  • Parameters

    Returns Promise<void>

    A promise that settles when the queue size is less than the given limit: queue.size < limit.

    If you want to avoid having the queue grow beyond a certain size you can await queue.onSizeLessThan() before adding a new item.

    Note that this only limits the number of items waiting to start. There could still be up to concurrency jobs already running that this call does not include in its calculation.