Commit | Line | Data |
---|---|---|
325f50bc S |
1 | const { DynamicThreadPool } = require('../../lib/index') |
2 | ||
3 | const size = 30 | |
4 | ||
5 | const dynamicPool = new DynamicThreadPool(size / 2, size * 3, './worker.js', { | |
6 | maxTasks: 10000 | |
7 | }) | |
8 | ||
9 | async function dynamicThreadTest ( | |
10 | { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } } | |
11 | ) { | |
12 | return new Promise((resolve, reject) => { | |
13 | let executions = 0 | |
14 | for (let i = 0; i <= tasks; i++) { | |
15 | dynamicPool | |
16 | .execute(workerData) | |
17 | .then(res => { | |
18 | executions++ | |
19 | if (executions === tasks) { | |
20 | return resolve('FINISH') | |
21 | } | |
22 | return null | |
23 | }) | |
24 | .catch(err => console.error(err)) | |
25 | } | |
26 | }) | |
27 | } | |
28 | ||
29 | module.exports = { dynamicThreadTest } |