libp2p
    Preparing search index...

    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 Summary)

    Index

    Constructors

    Properties

    concurrency: number
    maxSize: number

    Accessors

    Methods

    • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

      The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

      When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

      When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

      When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

      If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

      The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

      MDN Reference

      Type Parameters

      Parameters

      Returns void

    • 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.