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

Method onMessage

src/mcp/query-pool.ts:315–345  ·  view source on GitHub ↗
(w: PoolWorker, m: WorkerMessage)

Source from the content-addressed store, hash-verified

313 }
314
315 private onMessage(w: PoolWorker, m: WorkerMessage): void {
316 // Before the retired-worker check: destroy() waits on this for a worker
317 // it has already let go of.
318 if (m?.type === 'ready') this.startSettled(w);
319 if (!m || !this.workers.has(w)) return; // ignore late messages from retired workers
320 if (m.type === 'ready') {
321 if (!this.pendingWorkers.delete(w)) return; // already handled this handshake
322 if (m.ok === false) {
323 this.onWorkerGone(w); // failed opens consume the same budget as crashes
324 return;
325 }
326 this.everReady = true;
327 this.idle.push(w);
328 this.drain();
329 this.armIdleShrink(); // the last result may have come while this one started
330 return;
331 }
332 if (m.type === 'result') {
333 const job = this.inflight.get(w);
334 this.inflight.delete(w);
335 this.idle.push(w);
336 this.servedSinceShrink = true;
337 this.lastServer = w;
338 if (job) this.noteFinished(job);
339 if (job) this.settle(job, m.result ?? busyGuidance(0));
340 this.drain();
341 this.armIdleShrink();
342 return;
343 }
344 if (m.type === 'trimmed') this.replaceIfHeavy(w, m.heldBytes ?? 0);
345 }
346
347 /** Nothing queued or running, nothing starting, and every worker free. */
348 private get quiescent(): boolean {

Callers 1

spawnOneMethod · 0.95

Calls 12

startSettledMethod · 0.95
onWorkerGoneMethod · 0.95
drainMethod · 0.95
armIdleShrinkMethod · 0.95
noteFinishedMethod · 0.95
settleMethod · 0.95
replaceIfHeavyMethod · 0.95
busyGuidanceFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
deleteMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected