2 import { Worker, spawn } from 'threads'
3 // FINISH IMPORT LIBRARIES
4 const size = parseInt(process.env.POOL_SIZE)
5 const iterations = parseInt(process.env.NUM_ITERATIONS)
8 taskType: process.env.TASK_TYPE,
9 taskSize: parseInt(process.env.TASK_SIZE)
12 // Threads.js is not really a pool so we need to write few additional code
14 async function poolify () {
15 for (let i = 0; i < size; i++) {
16 const worker = await spawn(
17 new Worker('./workers/threadjs/function-to-bench-worker.mjs')
23 async function run () {
26 for (let i = 0; i < iterations; i++) {
27 const worker = workers[i % size]
28 promises.push(worker.exposedFunction(data))
30 await Promise.all(promises)
31 // eslint-disable-next-line n/no-process-exit