The callback execution pool that can execute limited number of callbacks in parallel while other submitted callbacks wait in the queue.

Constructors

Accessors

Methods

Constructors

  • Creates a new WorkPool instance that uses given number of workers.

    Parameters

    • size: number = 1

      The number of workers in the pool.

    Returns WorkPool

Accessors

  • get size(): number
  • The number of active workers in the pool.

    Returns number

Methods

  • Aborts all pending jobs and returns promise that is fulfilled when all workers are terminated.

    This operation preserves the size of the pool intact.

    Parameters

    • Optional reason: any

      The reason that is used to reject all pending job promises.

    Returns Promise<void>

    The promise that is fulfilled when all workers are terminated.

  • Changes the size of the pool by spawning or terminating workers. If the size of the pool is reduced, then corresponding workers are terminated and if they were processing jobs, those jobs are instantly aborted.

    Parameters

    • size: number

      The new size of the pool.

    • Optional reason: any

      The reason that is used to reject pending job promises that are processed by terminated workers. Only applicable if the pool is downsized.

    Returns Promise<void>

    The promise that is fulfilled when the number of workers matches the requested size: excessive workers were deleted or additional workers were spawned.

  • Submits a new callback that should be executed by the worker in the pool.

    Type Parameters

    • T

      The callback result.

    Parameters

    Returns AbortablePromise<T>

    The promise that is fulfilled with the callback result.