sync: update from private repo (0cddeaa)

This commit is contained in:
oss-sync
2026-06-04 00:34:55 +00:00
parent f5c7666f6b
commit 21be01b699
19 changed files with 1065 additions and 37 deletions
+16
View File
@@ -0,0 +1,16 @@
/**
* Minimal async mutex: serializes async sections via a promise chain. Each
* runExclusive call waits for the previous one to settle before starting, so
* critical sections never interleave across awaits. Rejections are isolated —
* a failing section does not break the chain for later callers.
*/
export class AsyncMutex {
private tail: Promise<unknown> = Promise.resolve();
runExclusive<T>(fn: () => Promise<T>): Promise<T> {
const result = this.tail.then(() => fn());
// Keep the chain alive regardless of this section's outcome.
this.tail = result.then(() => undefined, () => undefined);
return result;
}
}