const containerActionQueues = new Map>(); export async function serializeContainerAction( key: string, action: () => Promise, ): Promise { const previous = containerActionQueues.get(key) ?? Promise.resolve(); const next = previous.catch(() => undefined).then(action); containerActionQueues.set(key, next); try { return await next; } finally { if (containerActionQueues.get(key) === next) { containerActionQueues.delete(key); } } }