| 90 | // Each call holds in-flight until the gate opens, so max concurrency across |
| 91 | // the pool is observable: with size=5 and 5 calls, all 5 should run at once. |
| 92 | const behavior = (m: CallMsg): Action => ({ |
| 93 | wait: (async () => { |
| 94 | active++; maxActive = Math.max(maxActive, active); |
| 95 | await gate; |
| 96 | active--; |
| 97 | return ok(`r${m.id}`); |
| 98 | })(), |
| 99 | }); |
| 100 | const pool = new QueryPool({ root: '/x', size: 5, createWorker: () => new FakeWorker(behavior) }); |
| 101 | const calls = Promise.all(Array.from({ length: 5 }, (_, i) => pool.run('codegraph_search', { i }))); |
| 102 | await sleep(40); // let all workers spawn (cold-start cap → a few generations) + dispatch |