Logos DX
    Preparing search index...

    Function debounce

    • Delays the last call of a function for delay milliseconds and ignores all subsequent calls until the delay has passed.

      Type Parameters

      Parameters

      • fn: T

        function to debounce

      • opts: DebounceOptions

        options for the debounce function

      Returns DebouncedFunction<T>

      debounced function with flush and cancel methods

      const debouncedFn = debounce(fn, { delay: 1000 });
      debouncedFn(); // ignored
      await wait(500);
      debouncedFn(); // ignored
      await wait(500);
      debouncedFn(); // will call fn after 1000ms

      // Enhanced interface
      const result = debouncedFn.flush(); // execute immediately
      debouncedFn.cancel(); // prevent execution