/** Coalesce concurrent work for the same key into one in-flight promise. */ export function sharedInflight( inflight: Map>, key: string, start: () => Promise, ): Promise { 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; }