The return type of the function.
The async function to debounce.
Milliseconds to wait before executing.
Optionaloptions: DebounceOptionsDebounce configuration options.
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...");
}
Creates a debounced version of an async function. The function will only execute after the specified wait time has elapsed since the last call.