Interface ThrottledFunction<TArgs, TReturn>

Type Parameters

  • TArgs extends unknown[]

  • TReturn

Hierarchy

  • ThrottledFunction
  • Call the throttled function. Returns the value most recently-returned by the underlying function, or undefined if the function hasn't been called yet.

    Parameters

    • Rest ...args: TArgs

    Returns undefined | TReturn

Properties

clearCooldown: ((suppressQueuedInvocation?: boolean) => void)

Type declaration

    • (suppressQueuedInvocation?: boolean): void
    • Clears the current cooldown. If suppressQueuedInvocation is true, ignore/clear any queued invocation.

      Note: If there is a queued invocation and it is not suppressed, the underlying function will be executed and the cooldown will restart.

      Parameters

      • Optional suppressQueuedInvocation: boolean

      Returns void

clearQueuedInvocation: (() => void)

Type declaration

    • (): void
    • Clears the currently-queued invocation, if any.

      Returns void

forceFunctionCall: ((settings?: ForceFunctionCallSettings<TArgs>) => TReturn)

Type declaration

    • (settings?: ForceFunctionCallSettings<TArgs>): TReturn
    • Force calling the underlying function, bypassing the cooldown.

      Note: by default, calling this function will restart the cooldown period and clear any queued invocations. See ForceFunctionCallSettings to change this behavior.

      Returns

      The return value of the underlying function

      Parameters

      Returns TReturn

getCooldownHandle: (() => undefined | true | Timeout)

Type declaration

    • (): undefined | true | Timeout
    • Gets the internal handle for the current cooldown timeout. Use with caution!

      Returns

      undefined if there is no active cooldown.

      Returns

      true if the active cooldown is set to Infinity

      Returns

      a handle to the active cooldown timer.

      Returns undefined | true | Timeout

getReturnValue: (() => undefined | TReturn)

Type declaration

    • (): undefined | TReturn
    • Gets the most recent return value of the underlying function. If the function has not yet been called, returns undefined.

      Returns undefined | TReturn

getStats: (() => ThrottledFunctionStats)

Type declaration

isCoolingDown: (() => boolean)

Type declaration

    • (): boolean
    • Returns true if the throttled function is currently in a cooldown state

      Returns boolean

offCooldownComplete: ((callback: CooldownCompleteCallback<TArgs, TReturn>) => void)

Type declaration

onCooldownComplete: ((callback: CooldownCompleteCallback<TArgs, TReturn>) => void)

Type declaration

    • (callback: CooldownCompleteCallback<TArgs, TReturn>): void
    • Register a callback that is executed each time the cooldown ends. Return a boolean to force calling (true) or not calling (false) the underlying function, regardless of whether or not an invocation is queued.

      If multiple callbacks return competing true/false values, the behavior is undefined.

      Parameters

      Returns void

rawFunction: ((...args: TArgs) => TReturn)

Type declaration

    • (...args: TArgs): TReturn
    • Reference to the unmodified raw function. If this is called, it will not affect any cooldowns or queued invocations.

      Parameters

      • Rest ...args: TArgs

      Returns TReturn

resetCooldown: ((suppressQueuedInvocation?: boolean) => void)

Type declaration

    • (suppressQueuedInvocation?: boolean): void
    • Resets/sets the throttled function into a fresh cooldown period. If suppressQueuedInvocation is true, ignore/clear any queued invocation.

      Parameters

      • Optional suppressQueuedInvocation: boolean

      Returns void

setArgs: ((...args: TArgs) => void)

Type declaration

    • (...args: TArgs): void
    • Sets args to be passed to the underlying function in subsequent calls.

      Parameters

      • Rest ...args: TArgs

      Returns void

setCooldownPeriod: ((ms: number) => void)

Type declaration

    • (ms: number): void
    • Sets the cooldown period. All future cooldowns AFTER the currently running cooldown will use the new cooldown period.

      Parameters

      • ms: number

      Returns void

setQueuedInvocation: (() => void)

Type declaration

    • (): void
    • Sets a queued invocation for when the current cooldown period ends.

      Returns void

throttleSettings: ThrottleSettings

Reference to the settings object for this throttled function with all defaults populated.

Generated using TypeDoc