()
| 190 | } |
| 191 | |
| 192 | private spawnOne(): void { |
| 193 | if (this.destroyed || this.workers.size >= this.maxSize || !this.healthy) return; |
| 194 | let w: ParsePoolWorker; |
| 195 | try { |
| 196 | w = this.createWorker(); |
| 197 | } catch { |
| 198 | this.totalCrashes++; // counts toward the circuit breaker |
| 199 | return; |
| 200 | } |
| 201 | this.workers.add(w); |
| 202 | this.pending.add(w); |
| 203 | this.parseCounts.set(w, 0); |
| 204 | w.on('message', (m) => this.onMessage(w, (m ?? {}) as ParseWorkerMessage)); |
| 205 | w.on('error', (e) => this.onWorkerGone(w, `Worker error: ${e?.message ?? 'unknown'}`)); |
| 206 | w.on('exit', (code) => { if (code !== 0) this.onWorkerGone(w, `Worker exited with code ${code}`); }); |
| 207 | // Load grammars; the worker replies 'grammars-loaded' and only then is idle. |
| 208 | w.postMessage({ type: 'load-grammars', languages: this.languages }); |
| 209 | } |
| 210 | |
| 211 | private onMessage(w: ParsePoolWorker, m: ParseWorkerMessage): void { |
| 212 | if (m.type === 'grammars-loaded') { |
no test coverage detected