Skip to main content

debounce

function debounce<T, R>(fn, waitDuration): {
(this, ...args): Promise<R>;
cancel: () => void;
};

An higher-order-function that debounce a given function to only invoke after N amount of time passes since its last call.

Note: Can be extended in the future to allow immediate (leading) flag and cancel method options.

Type Parameters

Type Parameter
T extends unknown[]
R

Parameters

ParameterTypeDescription
fnFn<T, R>The function to throttle.
waitDurationnumberThe number of milliseconds to wait before invoke.

Returns

(this, ...args): Promise<R>;

Parameters

ParameterType
thisunknown
...argsT

Returns

Promise<R>

NameType
cancel()() => void