Creates a debounced version of an asynchronous function with cancellation support.
Only the last call within the specified delay is executed. All previous pending promises are rejected with a "Cancelled due to debounce" error.
Type of the async function to debounce.
The async function to debounce.
Milliseconds to wait before executing the function.
Debounced async function with .cancel() method.
.cancel()
const fetchData = async (q: string) => `Result for ${q}`;const debouncedFetch = debounceAsync(fetchData, 300);debouncedFetch("apple");debouncedFetch("banana"); // cancels "apple"await debouncedFetch("cherry");// → "Result for cherry" Copy
const fetchData = async (q: string) => `Result for ${q}`;const debouncedFetch = debounceAsync(fetchData, 300);debouncedFetch("apple");debouncedFetch("banana"); // cancels "apple"await debouncedFetch("cherry");// → "Result for cherry"
1.2.0
Creates a debounced version of an asynchronous function with cancellation support.
Only the last call within the specified delay is executed. All previous pending promises are rejected with a "Cancelled due to debounce" error.