X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fthread-worker.mjs;h=232881b52e77dfbe1669f0d27fe62f059206a8a6;hb=8258e525b4601510a20b909632f88a3604c7bc63;hp=c1cd01414830aa9eaaa88bd2d7a0a3d0a4854ab4;hpb=e102732c0e3966b81834b2c0bdd087eb051162ad;p=poolifier.git diff --git a/benchmarks/internal/thread-worker.mjs b/benchmarks/internal/thread-worker.mjs index c1cd0141..232881b5 100644 --- a/benchmarks/internal/thread-worker.mjs +++ b/benchmarks/internal/thread-worker.mjs @@ -1,16 +1,17 @@ -import { isMainThread } from 'worker_threads' -import { ThreadWorker } from '../../lib/index.mjs' -import { executeWorkerFunction } from '../benchmarks-utils.mjs' -import { WorkerFunctions } from '../benchmarks-types.mjs' +import { isMainThread } from 'node:worker_threads' -const debug = false +import { ThreadWorker } from '../../lib/index.mjs' +import { TaskFunctions } from '../benchmarks-types.cjs' +import { executeTaskFunction } from '../benchmarks-utils.mjs' -function workerFunction (data) { +const taskFunction = data => { data = data || {} - data.function = data.function || WorkerFunctions.jsonIntegerSerialization - executeWorkerFunction(data) - debug === true && console.debug('This is the main thread ' + isMainThread) - return { ok: 1 } + data.function = data.function || TaskFunctions.factorial + data.debug = data.debug || false + const res = executeTaskFunction(data) + data.debug === true && + console.debug(`This is the main thread ${isMainThread}`) + return res } -export default new ThreadWorker(workerFunction) +export default new ThreadWorker(taskFunction)