6 } = require('poolifier')
8 const pool = new DynamicThreadPool(
9 Math.floor(availableParallelism() / 2),
10 availableParallelism(),
13 errorHandler: e => console.error(e),
14 onlineHandler: () => console.info('worker is online')
20 pool.emitter?.on(PoolEvents.full, () => poolFull++)
21 pool.emitter?.on(PoolEvents.ready, () => poolReady++)
22 pool.emitter?.on(PoolEvents.busy, () => poolBusy++)
25 const start = performance.now()
26 const iterations = 1000
27 for (let i = 1; i <= iterations; i++) {
32 if (resolved === iterations) {
34 `Time taken is ${(performance.now() - start).toFixed(2)}ms`
36 console.info(`The pool was full for ${poolFull} times`)
37 console.info(`The pool was ready for ${poolReady} times`)
38 console.info(`The pool was busy for ${poolBusy} times`)
43 .catch(err => console.error(err))