const bundleChains = new Map>() export function serializeWorkspaceBundle( workspacePath: string, run: () => Promise ): Promise { const previous = bundleChains.get(workspacePath) ?? Promise.resolve() const current = previous.then(run, run) bundleChains.set(workspacePath, current) void current.then( () => { if (bundleChains.get(workspacePath) === current) bundleChains.delete(workspacePath) }, () => { if (bundleChains.get(workspacePath) === current) bundleChains.delete(workspacePath) } ) return current }