wishforge-ide/apps/ide/provisioner/run-operations.mjs
eust-w b47a07e8d2 chore: baseline snapshot of the Codex-delivered code before review
Imports the previously untracked working tree as-is so that the review
changes that follow (requirements -> design -> implementation) can be
reviewed as diffs and reverted if needed. No content changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:18:04 +08:00

13 lines
539 B
JavaScript

/** Serialize provision/cleanup for a run across generations in this provisioner process. */
export function createRunOperationQueue() {
const pending = new Map();
return async function runOperation(tenantId, runId, operation) {
const key = `${tenantId}\0${runId}`;
const previous = pending.get(key) ?? Promise.resolve();
const current = previous.catch(() => {}).then(operation);
pending.set(key, current);
try { return await current; }
finally { if (pending.get(key) === current) pending.delete(key); }
};
}