1 const { DynamicThreadPool
, PoolEvents
} = require('poolifier')
5 const pool
= new DynamicThreadPool(10, 20, './yourWorker.js', {
6 errorHandler
: e
=> console
.error(e
),
7 onlineHandler
: () => console
.log('worker is online')
9 pool
.emitter
.on(PoolEvents
.full
, () => poolFull
++)
10 pool
.emitter
.on(PoolEvents
.busy
, () => poolBusy
++)
12 const start
= performance
.now()
13 const iterations
= 1000
14 for (let i
= 1; i
<= iterations
; i
++) {
19 if (resolved
=== iterations
) {
20 console
.log('Time taken is ' + (performance
.now() - start
))
21 console
.log('The pool was full for ' + poolFull
+ ' times')
22 return console
.log('The pool was busy for ' + poolBusy
+ ' times')
26 .catch(err
=> console
.error(err
))