• Creates a debounced function that delays the given func by a given wait time in milliseconds. If the method is called again before the timeout expires, the previous call will be aborted.

    Type Parameters

    • T extends any[]

    Parameters

    • fn: ((this, ...args) => void)

      The function to debounce.

        • (this, ...args): void
        • Parameters

          • this: DebouncedFunction<T>
          • Rest ...args: T

          Returns void

    • wait: number

      The time in milliseconds to delay the function.

    Returns DebouncedFunction<T>

    Example

    const log = debounce(
      (event: Deno.FsEvent) =>
        console.log("[%s] %s", event.kind, event.paths[0]),
      200,
    );
    
    for await (const event of Deno.watchFs("./")) {
      log(event);
    }
    

    Forked from third-party library

    See

    https://github.com/denoland/deno_std/blob/main/async/debounce.ts

    Author

    The Deno authors

    License

    MIT