()
| 294 | private everReady = false; |
| 295 | |
| 296 | private spawnOne(): void { |
| 297 | if (this.destroyed || this.workers.size >= this.maxSize) return; |
| 298 | let w: PoolWorker; |
| 299 | try { |
| 300 | w = this.createWorker(); |
| 301 | } catch { |
| 302 | this.totalCrashes++; // counts toward the circuit breaker |
| 303 | return; |
| 304 | } |
| 305 | this.workers.add(w); |
| 306 | this.pendingWorkers.add(w); |
| 307 | let settle!: () => void; |
| 308 | const settled = new Promise<void>((resolve) => { settle = resolve; }); |
| 309 | this.starts.set(w, { settled, settle }); |
| 310 | w.on('message', (m) => this.onMessage(w, (m ?? {}) as WorkerMessage)); |
| 311 | w.on('error', () => { this.startSettled(w); this.onWorkerGone(w); }); |
| 312 | w.on('exit', (code) => { this.startSettled(w); this.retired(w); if (code !== 0) this.onWorkerGone(w); }); |
| 313 | } |
| 314 | |
| 315 | private onMessage(w: PoolWorker, m: WorkerMessage): void { |
| 316 | // Before the retired-worker check: destroy() waits on this for a worker |
no test coverage detected