Commit | Line | Data |
---|---|---|
a449b585 | 1 | import { isMainThread } from 'node:worker_threads' |
ded253e2 | 2 | |
8a970421 | 3 | import { ThreadWorker } from '../../lib/index.mjs' |
d35e5717 | 4 | import { TaskFunctions } from '../benchmarks-types.cjs' |
0804b9b4 | 5 | import { executeTaskFunction } from '../benchmarks-utils.mjs' |
8a970421 | 6 | |
041dc05b | 7 | const taskFunction = data => { |
8a970421 | 8 | data = data || {} |
66566c5d | 9 | data.function = data.function || TaskFunctions.factorial |
f1c674cd | 10 | data.debug = data.debug || false |
dbca3be9 | 11 | const res = executeTaskFunction(data) |
f1c674cd JB |
12 | data.debug === true && |
13 | console.debug(`This is the main thread ${isMainThread}`) | |
30b963d4 | 14 | return res |
8a970421 JB |
15 | } |
16 | ||
dbca3be9 | 17 | export default new ThreadWorker(taskFunction) |