Commit | Line | Data |
---|---|---|
60fbd6d6 | 1 | const { FixedThreadPool } = require('poolifier') |
c2dbbe2b | 2 | let resolved = 0 |
cf9aa6c3 | 3 | const pool = new FixedThreadPool(15, './yourWorker.js', { |
4 | errorHandler: e => console.error(e), | |
5 | onlineHandler: () => console.log('worker is online') | |
6 | }) | |
3e460d6d | 7 | |
27006a3d | 8 | const start = Date.now() |
bf962cba | 9 | const iterations = 1000 |
292ad316 | 10 | for (let i = 1; i <= iterations; i++) { |
583a27ce JB |
11 | pool |
12 | .execute({}) | |
13 | .then(res => { | |
14 | resolved++ | |
15 | if (resolved === iterations) { | |
16 | return console.log('Time take is ' + (Date.now() - start)) | |
17 | } | |
18 | return null | |
19 | }) | |
20 | .catch(err => console.error(err)) | |
6dc67cda | 21 | } |