evOo-local/apps/web/src/lib/shared-inflight.ts
cynarAI 6c7eed7580 Initial clean evOo-local from f00577b
Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline
(Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/*
packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
2026-09-20 17:15:16 +02:00

15 lines
437 B
TypeScript

/** Coalesce concurrent work for the same key into one in-flight promise. */
export function sharedInflight<T>(
inflight: Map<string, Promise<T>>,
key: string,
start: () => Promise<T>,
): Promise<T> {
const existing = inflight.get(key);
if (existing) return existing;
const promise = start().finally(() => {
if (inflight.get(key) === promise) inflight.delete(key);
});
inflight.set(key, promise);
return promise;
}