function to debounce
options for the debounce function
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
Delays the last call of a function for
delaymilliseconds and ignores all subsequent calls until the delay has passed.