Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PQueue<O>

Type parameters

Hierarchy

  • PQueue

Index

Type aliases

Static Task

Task: function

Type declaration

    • (): Promise<T>
    • Returns Promise<T>

Constructors

constructor

  • Parameters

    Returns PQueue

Properties

isPaused

isPaused: boolean

Whether the queue is currently paused.

pending

pending: number

Number of pending promises.

size

size: number

Size of the queue.

Methods

add

  • add<T>(fn: Task<T>, opts?: O): Promise<T>
  • Returns the promise returned by calling fn.

    Type parameters

    • T

    Parameters

    • fn: Task<T>

      Promise-returning/async function.

    • Optional opts: O

    Returns Promise<T>

addAll

  • addAll<TAll>(fns: Array<Task<TAll>>, opts?: O): Promise<TAll[]>
  • Same as .add(), but accepts an array of async functions and returns a promise that resolves when all async functions are resolved.

    Type parameters

    • TAll

    Parameters

    • fns: Array<Task<TAll>>
    • Optional opts: O

    Returns Promise<TAll[]>

clear

  • clear(): void
  • Clear the queue.

    Returns void

onEmpty

  • onEmpty(): Promise<void>
  • Returns a promise that settles when the queue becomes empty. Can be called multiple times. Useful if you for example add additional items at a later time.

    Returns Promise<void>

onIdle

  • onIdle(): Promise<void>
  • Returns a promise that settles when the queue becomes empty, and all promises have completed; queue.size === 0 && queue.pending === 0. 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.

    Returns Promise<void>

pause

  • pause(): void
  • Put queue execution on hold.

    Returns void

start

  • start(): void
  • Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via options.autoStart = false or by .pause() method.)

    Returns void

Generated using TypeDoc