Update main.yml
[poolifier.git] / dynamicExample.js
CommitLineData
bf962cba 1const DynamicThreadPool = require('./lib/dynamic')
2let resolved = 0
3let maxReached = 0
4const pool = new DynamicThreadPool(100, 200, './yourWorker.js', { errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') })
5pool.emitter.on('FullPool', () => maxReached++)
6
7const start = Date.now()
8const iterations = 1000
9for (let i = 0; i <= iterations; i++) {
10 pool.execute({}).then(res => {
11 resolved++
12 if (resolved === iterations) {
13 console.log('Time take is ' + (Date.now() - start))
14 console.log('The pool was full for ' + maxReached + ' times')
15 }
16 })
17}