Skip to main content

throttle

Callable

  • throttle<T>(fn: T, ms: number): (...args: Parameters<T>) => ReturnType<T>

  • Returns a new function that, when invoked repeatedly, invokes fn at most once per every ms milliseconds.

    @example
    const throttledFn = throttle((message) => {
    constole.log(message)
    }, 1000)

    Type parameters

    • T: (...args: any[]) => ReturnType<T>

    Parameters

    • fn: T

      The function to be throttled.

    • ms: number

      The number of milliseconds to throttle invocations to.

    Returns (...args: Parameters<T>) => ReturnType<T>

    A new function that wraps fn with throttling behavior.

      • (...args: Parameters<T>): ReturnType<T>
      • Parameters

        • rest...args: Parameters<T>

        Returns ReturnType<T>