MCPcopy
hub / github.com/colbymchenry/codegraph / drain

Method drain

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

Source from the content-addressed store, hash-verified

242 }
243
244 private drain(): void {
245 // Grow toward maxSize while queued work outstrips workers that are idle OR
246 // already on their way up (pending) — so we never spawn the whole pool for a
247 // single call whose eager worker just hasn't reported ready yet.
248 while (
249 this.queue.length > this.idle.length + this.pendingWorkers.size &&
250 this.workers.size < this.maxSize &&
251 this.pendingWorkers.size < MAX_CONCURRENT_SPAWN &&
252 this.healthy
253 ) {
254 this.spawnOne();
255 }
256 while (this.idle.length && this.queue.length) {
257 // Skip jobs the backstop already answered.
258 let job: Job | undefined;
259 while (this.queue.length && (job = this.queue.shift()) && job.settled) job = undefined;
260 if (!job || job.settled) break;
261 const w = this.idle.pop()!;
262 this.inflight.set(w, job);
263 w.postMessage({ type: 'call', id: job.id, toolName: job.toolName, args: job.args });
264 }
265 }
266
267 private settle(job: Job, result: ToolResult): void {
268 if (job.settled) return; // already answered (by backstop or worker)

Callers 3

onMessageMethod · 0.95
onWorkerGoneMethod · 0.95
runMethod · 0.95

Calls 3

spawnOneMethod · 0.95
setMethod · 0.80
postMessageMethod · 0.65

Tested by

no test coverage detected