5 } = require('poolifier')
7 const pool
= new DynamicThreadPool(
8 Math
.floor(availableParallelism() / 2),
9 availableParallelism(),
12 errorHandler
: e
=> console
.error(e
),
13 onlineHandler
: () => console
.info('worker is online')
19 pool
.emitter
.on(PoolEvents
.full
, () => poolFull
++)
20 pool
.emitter
.on(PoolEvents
.ready
, () => poolReady
++)
21 pool
.emitter
.on(PoolEvents
.busy
, () => poolBusy
++)
24 const start
= performance
.now()
25 const iterations
= 1000
26 for (let i
= 1; i
<= iterations
; i
++) {
31 if (resolved
=== iterations
) {
32 console
.info('Time taken is ' + (performance
.now() - start
))
33 console
.info('The pool was full for ' + poolFull
+ ' times')
34 console
.info('The pool was ready for ' + poolReady
+ ' times')
35 return console
.info('The pool was busy for ' + poolBusy
+ ' times')
39 .catch(err
=> console
.error(err
))