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

Method drain

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

Source from the content-addressed store, hash-verified

459 }
460
461 private drain(): void {
462 // Grow toward maxSize while queued work outstrips workers that are idle OR
463 // already on their way up (pending) — so we never spawn the whole pool for a
464 // single call whose eager worker just hasn't reported ready yet.
465 while (
466 this.queue.length > this.idle.length + this.pendingWorkers.size &&
467 this.workers.size < this.maxSize &&
468 this.pendingWorkers.size < MAX_CONCURRENT_SPAWN &&
469 this.healthy
470 ) {
471 this.spawnOne();
472 }
473 while (this.idle.length && this.queue.length) {
474 // Skip jobs the backstop already answered.
475 let job: Job | undefined;
476 while (this.queue.length && (job = this.queue.shift()) && job.settled) job = undefined;
477 if (!job || job.settled) break;
478 const w = this.idle.pop()!;
479 this.inflight.set(w, job);
480 job.startedAt = Date.now();
481 w.postMessage({ type: 'call', id: job.id, toolName: job.toolName, args: job.args });
482 }
483 }
484
485 private settle(job: Job, result: ToolResult): void {
486 if (job.settled) return; // already answered (by backstop or worker)

Callers 8

onMessageMethod · 0.95
onWorkerGoneMethod · 0.95
runMethod · 0.95
indexAllMethod · 0.45
syncMethod · 0.45
chainsMethod · 0.45

Calls 3

spawnOneMethod · 0.95
postMessageMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected