5 } = require('poolifier')
7 const pool
= new FixedThreadPool(availableParallelism(), './yourWorker.js', {
8 errorHandler
: e
=> console
.error(e
),
9 onlineHandler
: () => console
.info('worker is online')
13 pool
.emitter
.on(PoolEvents
.ready
, () => poolReady
++)
14 pool
.emitter
.on(PoolEvents
.busy
, () => poolBusy
++)
17 const start
= performance
.now()
18 const iterations
= 1000
19 for (let i
= 1; i
<= iterations
; i
++) {
24 if (resolved
=== iterations
) {
25 console
.info('Time taken is ' + (performance
.now() - start
))
26 console
.info('The pool was ready for ' + poolReady
+ ' times')
27 return console
.info('The pool was busy for ' + poolBusy
+ ' times')
31 .catch(err
=> console
.error(err
))