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

Method drain

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

Source from the content-addressed store, hash-verified

428 }
429
430 private drain(): void {
431 // Grow toward maxSize while queued work outstrips workers that are idle OR
432 // already on their way up (pending) — so we never spawn the whole pool for a
433 // single call whose eager worker just hasn't reported ready yet.
434 while (
435 this.queue.length > this.idle.length + this.pendingWorkers.size &&
436 this.workers.size < this.maxSize &&
437 this.pendingWorkers.size < MAX_CONCURRENT_SPAWN &&
438 this.healthy
439 ) {
440 this.spawnOne();
441 }
442 while (this.idle.length && this.queue.length) {
443 // Skip jobs the backstop already answered.
444 let job: Job | undefined;
445 while (this.queue.length && (job = this.queue.shift()) && job.settled) job = undefined;
446 if (!job || job.settled) break;
447 const w = this.idle.pop()!;
448 this.inflight.set(w, job);
449 w.postMessage({ type: 'call', id: job.id, toolName: job.toolName, args: job.args });
450 }
451 }
452
453 private settle(job: Job, result: ToolResult): void {
454 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