| 370 | } |
| 371 | |
| 372 | const flushStdout = async () => { |
| 373 | try { |
| 374 | if (!process.stdout.writable || process.stdout.destroyed) { |
| 375 | return |
| 376 | } |
| 377 | |
| 378 | await new Promise<void>((resolve, reject) => { |
| 379 | process.stdout.write("", (error?: Error | null) => { |
| 380 | if (error) { |
| 381 | reject(error) |
| 382 | return |
| 383 | } |
| 384 | |
| 385 | resolve() |
| 386 | }) |
| 387 | }) |
| 388 | } catch { |
| 389 | // Best effort: shutdown should proceed even if stdout flush fails. |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | const ensureKeepAliveInterval = () => { |
| 394 | if (!signalOnlyExit || keepAliveInterval) { |