MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / spawnOne

Method spawnOne

src/extraction/parse-pool.ts:318–340  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

316 }
317
318 private spawnOne(): void {
319 if (this.destroyed || this.workers.size >= this.maxSize || !this.healthy) return;
320 let w: ParsePoolWorker;
321 try {
322 w = this.createWorker();
323 } catch {
324 this.totalCrashes++; // counts toward the circuit breaker
325 return;
326 }
327 this.workers.add(w);
328 this.pending.add(w);
329 this.parseCounts.set(w, 0);
330 let settle!: () => void;
331 const settled = new Promise<void>((resolve) => { settle = resolve; });
332 this.loads.set(w, { settled, settle });
333 w.on('message', (m) => this.onMessage(w, (m ?? {}) as ParseWorkerMessage));
334 w.on('error', (e) => { this.loadSettled(w); this.onWorkerGone(w, `Worker error: ${e?.message ?? 'unknown'}`); });
335 w.on('exit', (code) => { this.loadSettled(w); if (code !== 0) this.onWorkerGone(w, `Worker exited with code ${code}`); });
336 // Load grammars; the worker replies 'grammars-loaded' and only then is idle.
337 // Pre-read WASM bytes (when the orchestrator provided them) make this a
338 // memory load instead of a per-spawn disk read.
339 w.postMessage({ type: 'load-grammars', languages: this.languages, grammarBuffers: this.grammarBuffers });
340 }
341
342 private onMessage(w: ParsePoolWorker, m: ParseWorkerMessage): void {
343 if (m.type === 'grammars-loaded') {

Callers 6

constructorMethod · 0.95
prewarmMethod · 0.95
onWorkerGoneMethod · 0.95
recycleMethod · 0.95
onHardTimeoutMethod · 0.95
drainMethod · 0.95

Calls 7

onMessageMethod · 0.95
loadSettledMethod · 0.95
onWorkerGoneMethod · 0.95
onMethod · 0.65
postMessageMethod · 0.65
addMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected