fix: fix dynamic import syntax
[poolifier.git] / examples / fixedExample.js
... / ...
CommitLineData
1const { FixedThreadPool, PoolEvents } = require('poolifier')
2let resolved = 0
3let poolBusy = 0
4const pool = new FixedThreadPool(15, './yourWorker.js', {
5 errorHandler: e => console.error(e),
6 onlineHandler: () => console.log('worker is online')
7})
8pool.emitter.on(PoolEvents.busy, () => poolBusy++)
9
10const start = performance.now()
11const iterations = 1000
12for (let i = 1; i <= iterations; i++) {
13 pool
14 .execute({})
15 .then(() => {
16 resolved++
17 if (resolved === iterations) {
18 console.log('Time taken is ' + (performance.now() - start))
19 return console.log('The pool was busy for ' + poolBusy + ' times')
20 }
21 return null
22 })
23 .catch(err => console.error(err))
24}