perf: remove unneeded class indirection for dynamic pool in worker
[poolifier.git] / examples / fixedExample.js
... / ...
CommitLineData
1const { FixedThreadPool } = require('poolifier')
2let resolved = 0
3const pool = new FixedThreadPool(15, './yourWorker.js', {
4 errorHandler: e => console.error(e),
5 onlineHandler: () => console.log('worker is online')
6})
7
8const start = Date.now()
9const iterations = 1000
10for (let i = 1; i <= iterations; i++) {
11 pool
12 .execute({})
13 .then(() => {
14 resolved++
15 if (resolved === iterations) {
16 return console.log('Time take is ' + (Date.now() - start))
17 }
18 return null
19 })
20 .catch(err => console.error(err))
21}