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

Method spawnOne

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

Source from the content-addressed store, hash-verified

265 private everReady = false;
266
267 private spawnOne(): void {
268 if (this.destroyed || this.workers.size >= this.maxSize) return;
269 let w: PoolWorker;
270 try {
271 w = this.createWorker();
272 } catch {
273 this.totalCrashes++; // counts toward the circuit breaker
274 return;
275 }
276 this.workers.add(w);
277 this.pendingWorkers.add(w);
278 let settle!: () => void;
279 const settled = new Promise<void>((resolve) => { settle = resolve; });
280 this.starts.set(w, { settled, settle });
281 w.on('message', (m) => this.onMessage(w, (m ?? {}) as WorkerMessage));
282 w.on('error', () => { this.startSettled(w); this.onWorkerGone(w); });
283 w.on('exit', (code) => { this.startSettled(w); this.retired(w); if (code !== 0) this.onWorkerGone(w); });
284 }
285
286 private onMessage(w: PoolWorker, m: WorkerMessage): void {
287 // 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