Type Parameters
- T extends unknown
- ARGS extends any[]
Parameters
- wait_time_ms: number
- fn: ((...args: ARGS) => T)
Returns ((...args: ARGS) => Promise<T>)
a function (that takes arguments intended for fn
) that returns a promise, which is resolved once wait_time_ms
amount of time has passed with no further calls
- (...args): Promise<T>
Returns Promise<T>
creates a debounced version of the provided function that returns a shared promise.
unlike conventional debounce, this function reuses and returns the same promise object for all calls that are made within the debouncing interval.
this means that all callers within this interval will receive the same promise, which will be resolved once
wait_time_ms
amount of time has passed with no further calls.if subsequent calls are made within the debouncing interval, the debounced function will return the same promise as before, further delaying its resolution.
however, once the debouncing interval has elapsed and the promise is resolved, any new calls to the debounced function will create and return a new promise.
Example