export async function singleFlight( flights: Map>, key: string, operation: () => Promise, ): Promise { const existing = flights.get(key) as Promise | undefined; if (existing) return existing; const pending = operation(); flights.set(key, pending); try { return await pending; } finally { if (flights.get(key) === pending) flights.delete(key); } }