Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Throttler<T, U, V>

Wraps and throttles a function that can be called multiple times and only executes the underlying function once per interval. A namespace for Throttler interfaces.

Type parameters

  • T

    The resolved type of the underlying function. Defaults to any.

  • U

    The rejected type of the underlying function. Defaults to any.

  • V: any[]

    Arguments for the underlying function. Defaults to any[].

Hierarchy

Implements

Index

Interfaces

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • Instantiate a throttler.

    Parameters

    • fn: function

      The function being throttled.

        • (...args: V): T | Promise<T>
        • Parameters

          • Rest ...args: V

          Returns T | Promise<T>

    • Optional options: IOptions | number

      Throttling configuration or throttling limit in ms.

      Notes

      The edge defaults to leading; the limit defaults to 500.

    Returns Throttler

Properties

Private _interval

_interval: number

Private _trailing

_trailing: boolean = false

Protected args

args: V | undefined = undefined

Arguments for the underlying function.

limit

limit: number

The rate limit in milliseconds.

Protected payload

payload: PromiseDelegate<T> | null = null

A promise that resolves on each successful invocation.

Protected poll

poll: Poll<T, U, "invoked">

The underlying poll instance used by the rate limiter.

Accessors

isDisposed

  • get isDisposed(): boolean

Methods

dispose

  • dispose(): void

invoke

  • invoke(...args: V): Promise<T>

stop

  • stop(): Promise<void>

Generated using TypeDoc