Name call serializers differently

This commit is contained in:
Vanilagy
2025-12-30 11:44:27 +01:00
parent aafb928460
commit 8467a9d672
5 changed files with 36 additions and 27 deletions
+24 -15
View File
@@ -675,20 +675,6 @@ export const computeRationalApproximation = (x: number, maxDenominator: number)
};
};
export class CallSerializer {
currentPromise = Promise.resolve();
errored = false;
call(fn: () => Promise<void> | void) {
return this.currentPromise = this.currentPromise
.then(fn)
.catch((error) => {
this.errored = true;
throw error;
});
}
}
let isWebKitCache: boolean | null = null;
export const isWebKit = () => {
if (isWebKitCache !== null) {
@@ -938,7 +924,30 @@ export class AsyncMutexLock implements Disposable {
}
}
export class CallSerializer2 {
/**
* A simple call serializer that works by chaining promises. When one callback throws, the serializer becomes bricked,
* meaning all future calls will also throw.
*/
export class NaiveCallSerializer {
currentPromise = Promise.resolve();
errored = false;
call(fn: () => Promise<void> | void) {
return this.currentPromise = this.currentPromise
.then(fn)
.catch((error) => {
this.errored = true;
throw error;
});
}
}
/**
* A more complex call serializer implementation that works with optionally asynchronous functions. It is forgiving
* in the sense that when a call throws, the error is surfaced but subsequent calls will go through again. So, it
* recovers.
*/
export class ForgivingCallSerializer {
private currentPromise: Promise<unknown> | null = null;
private queuedCalls = 0;