Home > @wixc3/common > delayed
Ensures func
will be called with at least wait
ms between runs.
Signature:
export declare function delayed<T extends (...args: any[]) => any>(fn: T, wait: number): (...args: Parameters<T>) => Promise<ReturnType<T>>;
Parameter | Type | Description |
---|---|---|
fn | T | |
wait | number |
Returns:
(…args: Parameters<T>) => Promise<ReturnType<T>>
// if `func` is called 3 times in a row:
func(1); func(2); func(3);
// it will wait `wait` ms between each run:
func(1);
await sleep(wait);
func(2);
await sleep(wait);
func(3);`
This is not throttling (!) since eventually all calls will be ran, while in throttling the calls in the “wait” period are skipped.