Function throttle

Limits the rate at which a function can be called.

const a = throttle(1000, (x: number) => x * 2);
a(1).then(console.log); // 2
a(2).then(console.log); // still 2, until 1000ms have passed
  • Type Parameters

    • Fn extends AnyFn

      The type of the function to be debounced.

    Parameters

    • duration: number

      The time in milliseconds to wait before executing the function.

    • fn: Fn

      The function to be debounced.

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

    A function that returns a promise with the result of the debounced function.

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

        • Rest...args: Parameters<Fn>

        Returns ReturnType<Fn>