| 1 | const DynamicThreadPool = require('../lib/dynamic') |
| 2 | let resolved = 0 |
| 3 | let maxReached = 0 |
| 4 | const pool = new DynamicThreadPool(10, 20, './yourWorker.js', { errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') }) |
| 5 | pool.emitter.on('FullPool', () => maxReached++) |
| 6 | |
| 7 | const start = Date.now() |
| 8 | const iterations = 1000 |
| 9 | for (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 | } |