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.
15 lines
437 B
TypeScript
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;
|
|
}
|