Function debounce

Debounces a function call, delaying its execution until a certain amount of time has passed without any new calls.

const a = debounce(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>) => Promise<ReturnType<Fn>>)

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

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

        • Rest...args: Parameters<Fn>

        Returns Promise<ReturnType<Fn>>