(step, timeoutMs = 120000)
| 4415 | const STEP_COMPLETION_SIGNAL_STEPS = new Set([3, 5, 9]); |
| 4416 | |
| 4417 | function waitForStepComplete(step, timeoutMs = 120000) { |
| 4418 | return new Promise((resolve, reject) => { |
| 4419 | throwIfStopped(); |
| 4420 | if (stepWaiters.has(step)) { |
| 4421 | console.warn(LOG_PREFIX, `[waitForStepComplete] replacing existing waiter for step ${step}`); |
| 4422 | } |
| 4423 | console.log(LOG_PREFIX, `[waitForStepComplete] register step ${step}, timeout=${timeoutMs}ms`); |
| 4424 | const timer = setTimeout(() => { |
| 4425 | stepWaiters.delete(step); |
| 4426 | console.warn(LOG_PREFIX, `[waitForStepComplete] timeout for step ${step} after ${timeoutMs}ms`); |
| 4427 | reject(new Error(`步骤 ${step} 等待超时(>${timeoutMs / 1000} 秒)`)); |
| 4428 | }, timeoutMs); |
| 4429 | |
| 4430 | stepWaiters.set(step, { |
| 4431 | resolve: (data) => { clearTimeout(timer); stepWaiters.delete(step); resolve(data); }, |
| 4432 | reject: (err) => { clearTimeout(timer); stepWaiters.delete(step); reject(err); }, |
| 4433 | }); |
| 4434 | }); |
| 4435 | } |
| 4436 | |
| 4437 | function doesStepUseCompletionSignal(step) { |
| 4438 | return STEP_COMPLETION_SIGNAL_STEPS.has(step); |
no test coverage detected