@vgerbot/async
    Preparing search index...

    Function debounce

    • Creates a debounced version of an async function. The function will only execute after the specified wait time has elapsed since the last call.

      Type Parameters

      • T

        The return type of the function.

      • Args extends unknown[] = unknown[]

      Parameters

      • fn: (...args: Args) => Promise<T>

        The async function to debounce.

      • wait: number

        Milliseconds to wait before executing.

      • Optionaloptions: DebounceOptions

        Debounce configuration options.

      Returns DebouncedFunction<T, Args>

      A debounced function with cancel, flush, and pending methods.

      const search = debounce(
      async (query: string) => {
      return await fetchResults(query);
      },
      300,
      );

      search("hello"); // Waits 300ms
      search("hello world"); // Cancels previous, waits 300ms

      // Cancel pending execution
      search.cancel();

      // Execute immediately
      search.flush();

      // Check if execution is pending
      if (search.pending()) {
      console.log("Waiting...");
      }