fn
createFilterWrapper
Wrap a function with an {@link EventFilter}, preserving arguments, `this`, and the return value through a promise. The wrapper returns a promise that resolves with the result of the wrapped function once the filter lets it through. When the filter coalesces calls (e.g. debounce/throttle), every pending promise scheduled since the last invocation resolves together with that invocation's result — so nothing is left dangling.
Signature
ts
export function createFilterWrapper<T extends AnyFunction>(
filter: EventFilter,
fn: T,
): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>>{ ... }Type Parameters
Textends AnyFunctionParameters
| Parameter | Type | Description |
|---|---|---|
filter | EventFilter | The event filter controlling invocation timing |
fn | T | The function to wrap |
Returns
(...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>>A filtered wrapper returning a promise of the result