R
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 AnyFunction

Parameters

ParameterTypeDescription
filterEventFilterThe event filter controlling invocation timing
fnTThe function to wrap

Returns

(...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>>A filtered wrapper returning a promise of the result