17 lines
327 B
JavaScript
17 lines
327 B
JavaScript
export function createSerializedRunner(task) {
|
|
let activePromise = null;
|
|
|
|
return function runSerialized(...args) {
|
|
if (activePromise) {
|
|
return activePromise;
|
|
}
|
|
|
|
activePromise = Promise.resolve(task(...args))
|
|
.finally(() => {
|
|
activePromise = null;
|
|
});
|
|
|
|
return activePromise;
|
|
};
|
|
}
|