ab7bb4f8 |
1 | const { isPrimary } = require('node:cluster') |
97231086 |
2 | |
d35e5717 |
3 | const { ClusterWorker } = require('../../lib/index.cjs') |
d35e5717 |
4 | const { TaskFunctions } = require('../benchmarks-types.cjs') |
97231086 |
5 | const { executeTaskFunction } = require('../benchmarks-utils.cjs') |
57df5469 |
6 | |
041dc05b |
7 | const taskFunction = data => { |
2d2e32c2 |
8 | data = data || {} |
66566c5d |
9 | data.function = data.function || TaskFunctions.factorial |
f1c674cd |
10 | data.debug = data.debug || false |
dbca3be9 |
11 | const res = executeTaskFunction(data) |
3a502712 |
12 | // eslint-disable-next-line @typescript-eslint/no-unused-expressions |
f1c674cd |
13 | data.debug === true && console.debug(`This is the main thread ${isPrimary}`) |
30b963d4 |
14 | return res |
106744f7 |
15 | } |
16 | |
ab7bb4f8 |
17 | module.exports = new ClusterWorker(taskFunction) |