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

Method drain

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

Source from the content-addressed store, hash-verified

260 }
261
262 private drain(): void {
263 // Grow toward maxSize while queued work outstrips workers that are idle OR
264 // already on their way up (pending) — so we never spawn the whole pool for a
265 // single call whose eager worker just hasn't reported ready yet.
266 while (
267 this.queue.length > this.idle.length + this.pendingWorkers.size &&
268 this.workers.size < this.maxSize &&
269 this.pendingWorkers.size < MAX_CONCURRENT_SPAWN &&
270 this.healthy
271 ) {
272 this.spawnOne();
273 }
274 while (this.idle.length && this.queue.length) {
275 // Skip jobs the backstop already answered.
276 let job: Job | undefined;
277 while (this.queue.length && (job = this.queue.shift()) && job.settled) job = undefined;
278 if (!job || job.settled) break;
279 const w = this.idle.pop()!;
280 this.inflight.set(w, job);
281 w.postMessage({ type: 'call', id: job.id, toolName: job.toolName, args: job.args });
282 }
283 }
284
285 private settle(job: Job, result: ToolResult): void {
286 if (job.settled) return; // already answered (by backstop or worker)

Callers 6

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

Calls 3

spawnOneMethod · 0.95
postMessageMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected