Commit | Line | Data |
---|---|---|
60fbd6d6 | 1 | const { DynamicThreadPool } = require('poolifier') |
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 | }) | |
330c983e | 8 | pool.emitter.on('busy', () => maxReached++) |
bf962cba | 9 | |
10 | const start = Date.now() | |
11 | const iterations = 1000 | |
292ad316 | 12 | for (let i = 1; i <= iterations; i++) { |
583a27ce JB |
13 | pool |
14 | .execute({}) | |
15 | .then(res => { | |
16 | resolved++ | |
17 | if (resolved === iterations) { | |
18 | console.log('Time take is ' + (Date.now() - start)) | |
a72f2599 | 19 | return console.log('The pool was busy for ' + maxReached + ' times') |
583a27ce JB |
20 | } |
21 | return null | |
22 | }) | |
23 | .catch(err => console.error(err)) | |
bf962cba | 24 | } |