A pool whose workers are light enough to keep, each answering with its own number.
(size: number, ready: (index: number) => boolean | null = () => true)
| 273 | |
| 274 | /** A pool whose workers are light enough to keep, each answering with its own number. */ |
| 275 | function keepingPool(size: number, ready: (index: number) => boolean | null = () => true) { |
| 276 | const workers: FakeWorker[] = []; |
| 277 | const pool = new QueryPool({ |
| 278 | root: '/x', size, idleShrinkMs: 5, idleKeepBytes: light, |
| 279 | createWorker: () => { |
| 280 | const index = workers.length; |
| 281 | const worker = new FakeWorker(() => ({ result: ok(`worker ${index}`) }), ready(index)); |
| 282 | worker.heldBytes = light; |
| 283 | workers.push(worker); |
| 284 | return worker; |
| 285 | }, |
| 286 | }); |
| 287 | return { pool, workers }; |
| 288 | } |
| 289 | |
| 290 | it('answers the first call after idle on the worker already running, starting none', async () => { |
| 291 | const { pool, workers } = keepingPool(2); |
no test coverage detected