Home > @wixc3/common > enforceSequentialExecution
Ensures that when the async function fn
is called twice in a row, the second call only begins after the first one has finished (successfully or not).
Signature:
export declare function enforceSequentialExecution<P, T extends (...args: any[]) => Promise<Awaited<P>>>(fn: T): T;
Parameter | Type | Description |
---|---|---|
fn | T |
Returns:
T
const doWork = enforceSequentialExecution(() => {
console.log('start');
await sleep(1000);
console.log('end');
});
void doWork();
void doWork();
// Result: start, end, start, end