Commit | Line | Data |
---|---|---|
74750c7f | 1 | async function runPoolifierTest (pool, { tasks, workerData }) { |
ff5e76e1 JB |
2 | return new Promise((resolve, reject) => { |
3 | let executions = 0 | |
292ad316 | 4 | for (let i = 1; i <= tasks; i++) { |
ff5e76e1 JB |
5 | pool |
6 | .execute(workerData) | |
7 | .then(res => { | |
8 | executions++ | |
9 | if (executions === tasks) { | |
10 | return resolve('FINISH') | |
11 | } | |
12 | return null | |
13 | }) | |
14 | .catch(err => console.error(err)) | |
15 | } | |
16 | }) | |
17 | } | |
18 | ||
74750c7f | 19 | function generateRandomInteger (max, min = 0) { |
c2d7d79b | 20 | max = Math.floor(max) |
74750c7f | 21 | if (min) { |
c2d7d79b | 22 | min = Math.ceil(min) |
872585ea | 23 | return Math.floor(Math.random() * (max - min + 1)) + min |
74750c7f | 24 | } |
872585ea | 25 | return Math.floor(Math.random() * (max + 1)) |
74750c7f JB |
26 | } |
27 | ||
292ad316 JB |
28 | const LIST_FORMATTER = new Intl.ListFormat('en-US', { |
29 | style: 'long', | |
30 | type: 'conjunction' | |
31 | }) | |
32 | ||
33 | module.exports = { generateRandomInteger, LIST_FORMATTER, runPoolifierTest } |