Options
All
  • Public
  • Public/Protected
  • All
Menu

PQueue with synchronous add and a common error-handler.

Hierarchy

  • TaskQueue

Implements

Index

Constructors

Accessors

Methods

Constructors

constructor

  • new TaskQueue(onError?: (error: Error, retry: () => void) => void): TaskQueue
  • Construct the queue.

    Parameters

    • Default value onError: (error: Error, retry: () => void) => void = noop

      Common error handler for all the tasks, it is called whenever a task errors. The first parameter is an error object. The second parameter, if called, would re-add the task to the queue again. Useful if you know an error indicates another attempt to execute the task is necessary.

        • (error: Error, retry: () => void): void
        • Parameters

          • error: Error
          • retry: () => void
              • (): void
              • Returns void

          Returns void

    Returns TaskQueue

Accessors

size

  • get size(): number

Methods

add

  • add(task: any, onFinally?: any): void

clear

  • clear(): void

onIdle

  • onIdle(): Promise<void>

pause

  • pause(): void

run

  • run<T>(task: Task<T>): Promise<T>
  • Add task and wait till it is completed. The point of run (as opposed to add) is to pass an error to the caller if it is throw inside a task. Note "fire-and-forget" comment for the add method.

    Type parameters

    • T

    Parameters

    Returns Promise<T>