* 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)
| 503 | * see that constant for the crash this avoids). |
| 504 | */ |
| 505 | private async terminateStarted(w: PoolWorker): Promise<void> { |
| 506 | const start = this.starts.get(w); |
| 507 | if (start) { |
| 508 | let cap: NodeJS.Timeout | undefined; |
| 509 | await Promise.race([ |
| 510 | start.settled, |
| 511 | new Promise<void>((resolve) => { cap = setTimeout(resolve, this.startSettleMs); cap.unref?.(); }), |
| 512 | ]); |
| 513 | clearTimeout(cap); |
| 514 | } |
| 515 | try { await w.terminate(); } catch { /* already gone */ } |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * Terminate all workers and answer any outstanding calls gracefully. A worker |