Fixes and improvements

This commit is contained in:
2026-07-07 09:29:56 +03:00
parent 784ce673b6
commit ba37eabea9
6 changed files with 238 additions and 15 deletions
+27
View File
@@ -0,0 +1,27 @@
type Job<T> = () => Promise<T>;
let tail = Promise.resolve();
let pendingJobs = 0;
export function queueSequential<T>(job: Job<T>): Promise<T> {
pendingJobs += 1;
const run = tail.then(async () => {
try {
return await job();
} finally {
pendingJobs -= 1;
}
});
tail = run.then(
() => undefined,
() => undefined
);
return run;
}
export function queuedJobCount() {
return pendingJobs;
}