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

Method spawnOne

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

Source from the content-addressed store, hash-verified

341 }
342
343 private spawnOne(): void {
344 if (this.destroyed || this.workers.size >= this.maxSize || !this.healthy) return;
345 let w: ParsePoolWorker;
346 try {
347 w = this.createWorker();
348 } catch {
349 this.totalCrashes++; // counts toward the circuit breaker
350 return;
351 }
352 this.workers.add(w);
353 this.pending.add(w);
354 this.parseCounts.set(w, 0);
355 let settle!: () => void;
356 const settled = new Promise<void>((resolve) => { settle = resolve; });
357 this.loads.set(w, { settled, settle });
358 w.on('message', (m) => this.onMessage(w, (m ?? {}) as ParseWorkerMessage));
359 w.on('error', (e) => { this.loadSettled(w); this.onWorkerGone(w, `Worker error: ${e?.message ?? 'unknown'}`); });
360 w.on('exit', (code) => { this.loadSettled(w); if (code !== 0) this.onWorkerGone(w, `Worker exited with code ${code}`); });
361 // Load grammars; the worker replies 'grammars-loaded' and only then is idle.
362 // Pre-read WASM bytes (when the orchestrator provided them) make this a
363 // memory load instead of a per-spawn disk read.
364 w.postMessage({ type: 'load-grammars', languages: this.languages, grammarBuffers: this.grammarBuffers });
365 }
366
367 private onMessage(w: ParsePoolWorker, m: ParseWorkerMessage): void {
368 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