( streams: readonly Writable[], timeoutMs: number = HEADLESS_STDIO_DRAIN_TIMEOUT_MS, )
| 61 | * wait is bounded so a permanently-stuck consumer can't re-introduce the hang. |
| 62 | */ |
| 63 | export async function drainStdio( |
| 64 | streams: readonly Writable[], |
| 65 | timeoutMs: number = HEADLESS_STDIO_DRAIN_TIMEOUT_MS, |
| 66 | ): Promise<void> { |
| 67 | let timer: NodeJS.Timeout | undefined; |
| 68 | const timeout = new Promise<void>((resolve) => { |
| 69 | timer = setTimeout(resolve, timeoutMs); |
| 70 | timer.unref?.(); |
| 71 | }); |
| 72 | try { |
| 73 | await Promise.race([Promise.all(streams.map(flushStream)).then(() => undefined), timeout]); |
| 74 | } finally { |
| 75 | if (timer !== undefined) clearTimeout(timer); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Finalize a completed headless run: flush stdio, then arm the force-exit |
no outgoing calls
no test coverage detected