()
| 265 | private everReady = false; |
| 266 | |
| 267 | private spawnOne(): void { |
| 268 | if (this.destroyed || this.workers.size >= this.maxSize) return; |
| 269 | let w: PoolWorker; |
| 270 | try { |
| 271 | w = this.createWorker(); |
| 272 | } catch { |
| 273 | this.totalCrashes++; // counts toward the circuit breaker |
| 274 | return; |
| 275 | } |
| 276 | this.workers.add(w); |
| 277 | this.pendingWorkers.add(w); |
| 278 | let settle!: () => void; |
| 279 | const settled = new Promise<void>((resolve) => { settle = resolve; }); |
| 280 | this.starts.set(w, { settled, settle }); |
| 281 | w.on('message', (m) => this.onMessage(w, (m ?? {}) as WorkerMessage)); |
| 282 | w.on('error', () => { this.startSettled(w); this.onWorkerGone(w); }); |
| 283 | w.on('exit', (code) => { this.startSettled(w); this.retired(w); if (code !== 0) this.onWorkerGone(w); }); |
| 284 | } |
| 285 | |
| 286 | private onMessage(w: PoolWorker, m: WorkerMessage): void { |
| 287 | // Before the retired-worker check: destroy() waits on this for a worker |
no test coverage detected