()
| 184 | } |
| 185 | |
| 186 | private spawnOne(): void { |
| 187 | if (this.destroyed || this.workers.size >= this.maxSize) return; |
| 188 | let w: PoolWorker; |
| 189 | try { |
| 190 | w = this.createWorker(); |
| 191 | } catch { |
| 192 | this.totalCrashes++; // counts toward the circuit breaker |
| 193 | return; |
| 194 | } |
| 195 | this.workers.add(w); |
| 196 | this.pendingWorkers.add(w); |
| 197 | w.on('message', (m) => this.onMessage(w, (m ?? {}) as WorkerMessage)); |
| 198 | w.on('error', () => this.onWorkerGone(w)); |
| 199 | w.on('exit', (code) => { if (code !== 0) this.onWorkerGone(w); }); |
| 200 | } |
| 201 | |
| 202 | private onMessage(w: PoolWorker, m: WorkerMessage): void { |
| 203 | if (!m) return; |
no test coverage detected