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

Method spawnOne

src/mcp/query-pool.ts:296–313  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 4

constructorMethod · 0.95
replaceIfHeavyMethod · 0.95
onWorkerGoneMethod · 0.95
drainMethod · 0.95

Calls 7

onMessageMethod · 0.95
startSettledMethod · 0.95
onWorkerGoneMethod · 0.95
retiredMethod · 0.95
onMethod · 0.65
addMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected