A limiter is a queue system that allows you to control the rate of job processing. It can be used to limit the number of concurrent jobs, the delay between each job, the maximum number of jobs in the queue, and the strategy to use when the queue length reaches highWater.

Hierarchy (View Summary)

Constructors

Accessors

  • get pending(): number
  • Returns the number of pending jobs

    Returns number

  • get size(): number
  • Returns the number of jobs in the queue

    Returns number

Methods

  • Register an event listener over the done event, which is emitted when a task has ended, either due to completion or failure.

    Parameters

    • event: string

      done event

    • listener: DoneListener

      Done event listener

    Returns this

  • Register an event listener over the refill event, which is emitted when queue bucket is refilled

    Parameters

    • event: "refill"

      refill event

    • listener: () => void

      Refill event listener

    Returns this

  • Register an event listener over the seed event, which is emitted when queue is empty and a new task is added

    Parameters

    • event: "seed"

      seed event

    • listener: () => void

      The listener function to add

    Returns this

  • Executes a task and returns a promise that resolves when the task is done

    Type Parameters

    • T
    • U

    Parameters

    Returns Promise<T>

    A promise that resolves when the task is done

  • Executes a task and returns a promise that resolves when the task is done

    Type Parameters

    • T
    • U

    Parameters

    Returns Promise<T>

    A promise that resolves when the task is done

  • Removes the specified listener from the listener array for the done event.

    Parameters

    • event: string

      done event

    • listener: DoneListener

      The listener function to remove

    Returns this

  • Removes the specified listener from the listener array for the refill event.

    Parameters

    • event: "refill"

      refill event

    • listener: () => void

      The listener function to remove

    Returns this

  • Removes the specified listener from the listener array for the seed event.

    Parameters

    • event: "seed"

      seed event

    • listener: () => void

      The listener function to remove

    Returns this

  • Register an event listener over the done event, which is emitted when a task has ended, either due to completion or failure.

    Parameters

    • event: string

      done event

    • listener: DoneListener

      Done event listener

    Returns this

  • Register an event listener over the refill event, which is emitted when queue bucket is refilled

    Parameters

    • event: "refill"

      refill event

    • listener: () => void

      Refill event listener

    Returns this

  • Register an event listener over the seed event, which is emitted when queue is empty and a new task is added

    Parameters

    • event: "seed"

      seed event

    • listener: () => void

      The listener function to add

    Returns this

  • Registers a one-time event listener over the done event, which is emitted when a task has ended, either due to completion or failure.

    Parameters

    • event: string

      done event

    • listener: DoneListener

      Done event listener

    Returns this

  • Registers a one-time event listener over the refill event, which is emitted when queue bucket is refilled

    Parameters

    • event: "refill"

      refill event

    • listener: () => void

      Refill event listener

    Returns this

  • Registers a one-time event listener over the seed event, which is emitted when queue is empty and a new task is added

    Parameters

    • event: "seed"

      seed event

    • listener: () => void

      The listener function to add

    Returns this

  • Pipes the limiter to another limiter

    Parameters

    Returns void

  • Registers a event listener over the done event, at the beginning of the listeners array, which is emitted when a task has ended, either due to completion or failure.

    Parameters

    • event: string

      done event

    • listener: DoneListener

      Done event listener

    Returns this

  • Registers a event listener over the refill event, at the beginning of the listeners array, which is emitted when queue bucket is refilled

    Parameters

    • event: "refill"

      refill event

    • listener: () => void

      Refill event listener

    Returns this

  • Registers a event listener over the seed event, at the beginning of the listeners array, which is emitted when queue is empty and a new task is added

    Parameters

    • event: "seed"

      seed event

    • listener: () => void

      The listener function to add

    Returns this

  • Registers a one-time event listener over the done event, at the beginning of the listeners array, which is emitted when a task has ended, either due to completion or failure.

    Parameters

    • event: string

      done event

    • listener: DoneListener

      Done event listener

    Returns this

  • Registers a one-time event listener over the refill event, at the beginning of the listeners array, which is emitted when queue bucket is refilled

    Parameters

    • event: "refill"

      refill event

    • listener: () => void

      Refill event listener

    Returns this

  • Registers a one-time event listener over the seed event, at the beginning of the listeners array, which is emitted when queue is empty and a new task is added

    Parameters

    • event: "seed"

      seed event

    • listener: () => void

      The listener function to add

    Returns this

  • Removes all listeners, or those of the specified event.

    Parameters

    • Optionalevent: "done"

      done event

    Returns this

  • Removes all listeners, or those of the specified event.

    Parameters

    • Optionalevent: "refill"

      refill event

    Returns this

  • Removes all listeners, or those of the specified event.

    Parameters

    • Optionalevent: "seed"

      seed event

    Returns this

  • Removes the specified listener from the listener array for the done event.

    Parameters

    • event: string

      done event

    • listener: DoneListener

      The listener function to remove

    Returns this

  • Removes the specified listener from the listener array for the refill event.

    Parameters

    • event: "refill"

      refill event

    • listener: () => void

      The listener function to remove

    Returns this

  • Removes the specified listener from the listener array for the seed event.

    Parameters

    • event: "seed"

      seed event

    • listener: () => void

      The listener function to remove

    Returns this

  • Schedules a task to be executed by the limiter

    Type Parameters

    • T
    • U

    Parameters

    Returns undefined | string

    The task handler

  • Schedules a task to be executed by the limiter

    Type Parameters

    • T
    • U

    Parameters

    Returns undefined | string

    The task handler

  • Starts the limiter

    Returns void

  • Stops the limiter

    Returns void

  • Waits until the queue is empty

    Returns Promise<void>