README.md: Small refinements
[poolifier.git] / benchmarks / thread / dynamic.js
CommitLineData
325f50bc
S
1const { DynamicThreadPool } = require('../../lib/index')
2
3const size = 30
4
5const dynamicPool = new DynamicThreadPool(size / 2, size * 3, './worker.js', {
6 maxTasks: 10000
7})
8
9async 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
29module.exports = { dynamicThreadTest }