757c6961ec09f701c4db37de3cbd8a78c43f8cab
[poolifier.git] / benchmarks / internal / cluster-worker.cjs
1 const { isPrimary } = require('node:cluster')
2
3 const { ClusterWorker } = require('../../lib/index.cjs')
4 const { TaskFunctions } = require('../benchmarks-types.cjs')
5 const { executeTaskFunction } = require('../benchmarks-utils.cjs')
6
7 const taskFunction = data => {
8 data = data || {}
9 data.function = data.function || TaskFunctions.factorial
10 data.debug = data.debug || false
11 const res = executeTaskFunction(data)
12 // eslint-disable-next-line @typescript-eslint/no-unused-expressions
13 data.debug === true && console.debug(`This is the main thread ${isPrimary}`)
14 return res
15 }
16
17 module.exports = new ClusterWorker(taskFunction)