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
) {
33 console
.info('Time taken is ' + (performance
.now() - start
))
34 console
.info('The pool was full for ' + poolFull
+ ' times')
35 console
.info('The pool was ready for ' + poolReady
+ ' times')
36 return console
.info('The pool was busy for ' + poolBusy
+ ' times')
40 .catch((err
) => console
.error(err
))