Commit | Line | Data |
---|---|---|
60fbd6d6 | 1 | const { DynamicThreadPool } = require('poolifier') |
bf962cba | 2 | let resolved = 0 |
164d950a JB |
3 | let poolFull = 0 |
4 | let poolBusy = 0 | |
cf9aa6c3 | 5 | const pool = new DynamicThreadPool(10, 20, './yourWorker.js', { |
6 | errorHandler: e => console.error(e), | |
7 | onlineHandler: () => console.log('worker is online') | |
8 | }) | |
164d950a JB |
9 | pool.emitter.on('full', () => poolFull++) |
10 | pool.emitter.on('busy', () => poolBusy++) | |
bf962cba | 11 | |
12 | const start = Date.now() | |
13 | const iterations = 1000 | |
292ad316 | 14 | for (let i = 1; i <= iterations; i++) { |
583a27ce JB |
15 | pool |
16 | .execute({}) | |
7a6a0a96 | 17 | .then(() => { |
583a27ce JB |
18 | resolved++ |
19 | if (resolved === iterations) { | |
164d950a JB |
20 | console.log('Time taken is ' + (Date.now() - start)) |
21 | console.log('The pool was full for ' + poolFull + ' times') | |
22 | return console.log('The pool was busy for ' + poolBusy + ' times') | |
583a27ce JB |
23 | } |
24 | return null | |
25 | }) | |
26 | .catch(err => console.error(err)) | |
bf962cba | 27 | } |