| 1 | const { FixedClusterPool } = require('../../../lib/index') |
| 2 | |
| 3 | const size = 30 |
| 4 | |
| 5 | const fixedPool = new FixedClusterPool( |
| 6 | size, |
| 7 | './benchmarks/internal/cluster/worker.js', |
| 8 | { |
| 9 | maxTasks: 10000 |
| 10 | } |
| 11 | ) |
| 12 | |
| 13 | async function fixedClusterTest ( |
| 14 | { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } } |
| 15 | ) { |
| 16 | return new Promise((resolve, reject) => { |
| 17 | let executions = 0 |
| 18 | for (let i = 0; i <= tasks; i++) { |
| 19 | fixedPool |
| 20 | .execute(workerData) |
| 21 | .then(res => { |
| 22 | executions++ |
| 23 | if (executions === tasks) { |
| 24 | return resolve('FINISH') |
| 25 | } |
| 26 | return null |
| 27 | }) |
| 28 | .catch(err => { |
| 29 | console.error(err) |
| 30 | }) |
| 31 | } |
| 32 | }) |
| 33 | } |
| 34 | |
| 35 | module.exports = { fixedClusterTest } |