* Terminate a worker, but not while it is still starting up: wait for it to * post 'ready' (or go away), up to `startSettleMs` (WORKER_START_SETTLE_MS — * see that constant for the crash this avoids).
(w: PoolWorker)
| 490 | * see that constant for the crash this avoids). |
| 491 | */ |
| 492 | private async terminateStarted(w: PoolWorker): Promise<void> { |
| 493 | const start = this.starts.get(w); |
| 494 | if (start) { |
| 495 | let cap: NodeJS.Timeout | undefined; |
| 496 | await Promise.race([ |
| 497 | start.settled, |
| 498 | new Promise<void>((resolve) => { cap = setTimeout(resolve, this.startSettleMs); cap.unref?.(); }), |
| 499 | ]); |
| 500 | clearTimeout(cap); |
| 501 | } |
| 502 | try { await w.terminate(); } catch { /* already gone */ } |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * Terminate all workers and answer any outstanding calls gracefully. A worker |