Parameters
- fn: (...args: T) => R
- wait: number
- immediate: boolean = false
Returns (...args: T) => Promise<R | undefined>
A debounced version of the input function. Each call returns a Promise that resolves
with the function's return value, or undefined if the call was cancelled by a subsequent call.
Creates a debounced version of a function, which will only be invoked after a specified delay has passed since the last time the debounced function was invoked. If
immediateis true, the function will be triggered at the start of the debounce delay, otherwise, it is triggered after.Each call returns a Promise that resolves with the function's return value when that specific invocation leads to execution. Calls that are cancelled by a subsequent invocation within the wait window resolve with
undefined.This is useful for scenarios like limiting the rate of user input handling, resizing events, or scroll events.
Example: