* 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)
| 575 | * see that constant for the crash this avoids). |
| 576 | */ |
| 577 | private async terminateStarted(w: PoolWorker): Promise<void> { |
| 578 | const start = this.starts.get(w); |
| 579 | if (start) { |
| 580 | let cap: NodeJS.Timeout | undefined; |
| 581 | await Promise.race([ |
| 582 | start.settled, |
| 583 | new Promise<void>((resolve) => { cap = setTimeout(resolve, this.startSettleMs); cap.unref?.(); }), |
| 584 | ]); |
| 585 | clearTimeout(cap); |
| 586 | } |
| 587 | try { await w.terminate(); } catch { /* already gone */ } |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Terminate all workers and answer any outstanding calls gracefully. A worker |