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