Update README.MD
[poolifier.git] / examples / dynamicExample.js
CommitLineData
c68d4281 1const DynamicThreadPool = require('../lib/dynamic')
bf962cba 2let resolved = 0
3let maxReached = 0
75b44e22 4const pool = new DynamicThreadPool(10, 20, './yourWorker.js', { errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') })
bf962cba 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}