Files
immich/web/src/lib/utils/invocationTracker.ts
T
midzelis e79a98fa82 feat(web): view transitions from timeline to viewer
Change-Id: I0a37b417ee4c247dcc93d442c976eede6a6a6964
2026-03-24 15:43:06 +00:00

37 lines
914 B
TypeScript

export class InvocationTracker {
invocationsStarted = 0;
invocationsEnded = 0;
startInvocation() {
this.invocationsStarted++;
const invocation = this.invocationsStarted;
return {
isStillValid: () => invocation === this.invocationsStarted,
endInvocation: () => {
this.invocationsEnded = Math.max(this.invocationsEnded, invocation);
},
};
}
isActive() {
return this.invocationsStarted !== this.invocationsEnded;
}
async invoke<T>(invocable: () => Promise<T>, catchCallback?: (error: unknown) => void, finallyCallback?: () => void) {
const invocation = this.startInvocation();
try {
return await invocable();
} catch (error: unknown) {
if (catchCallback) {
catchCallback(error);
} else {
console.error(error);
}
} finally {
invocation.endInvocation();
finallyCallback?.();
}
}
}