From: Jérôme Benoit Date: Wed, 2 Aug 2023 13:16:12 +0000 (+0200) Subject: refactor: code cleanups X-Git-Tag: v2.6.21~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=440dd7d77da6e027b3b9543504addcf805f76c1d;p=poolifier.git refactor: code cleanups Signed-off-by: Jérôme Benoit --- diff --git a/benchmarks/internal/cluster-worker.mjs b/benchmarks/internal/cluster-worker.mjs index efbcf7b1..60876beb 100644 --- a/benchmarks/internal/cluster-worker.mjs +++ b/benchmarks/internal/cluster-worker.mjs @@ -5,7 +5,7 @@ import { TaskFunctions } from '../benchmarks-types.mjs' const debug = false -function taskFunction (data) { +const taskFunction = data => { data = data || {} data.function = data.function || TaskFunctions.jsonIntegerSerialization const res = executeTaskFunction(data) diff --git a/benchmarks/internal/thread-worker.mjs b/benchmarks/internal/thread-worker.mjs index e56eaa4c..869e95f4 100644 --- a/benchmarks/internal/thread-worker.mjs +++ b/benchmarks/internal/thread-worker.mjs @@ -5,7 +5,7 @@ import { TaskFunctions } from '../benchmarks-types.mjs' const debug = false -function taskFunction (data) { +const taskFunction = data => { data = data || {} data.function = data.function || TaskFunctions.jsonIntegerSerialization const res = executeTaskFunction(data) diff --git a/benchmarks/versus-external-pools/functions/function-to-bench.js b/benchmarks/versus-external-pools/functions/function-to-bench.js index 5c63c794..ecc39a1c 100644 --- a/benchmarks/versus-external-pools/functions/function-to-bench.js +++ b/benchmarks/versus-external-pools/functions/function-to-bench.js @@ -5,7 +5,7 @@ * @param {*} data The worker data. * @returns {*} The result. */ -module.exports = function functionToBench (data) { +const functionToBench = data => { const crypto = require('crypto') const fs = require('fs') const TaskTypes = { @@ -48,3 +48,5 @@ module.exports = function functionToBench (data) { throw new Error(`Unknown task type: ${data.taskType}`) } } + +module.exports = functionToBench diff --git a/benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.mjs b/benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.mjs index c49013c3..8515b1dc 100644 --- a/benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.mjs +++ b/benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.mjs @@ -1,7 +1,7 @@ import workerpool from 'workerpool' import functionToBench from '../../functions/function-to-bench.js' -function wrapperFunctionToBench (testName, taskType, taskSize) { +const functionToBenchWrapper = (testName, taskType, taskSize) => { return functionToBench({ test: testName, taskType, @@ -10,5 +10,5 @@ function wrapperFunctionToBench (testName, taskType, taskSize) { } workerpool.worker({ - functionToBench: wrapperFunctionToBench + functionToBench: functionToBenchWrapper }) diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 1b34fb13..381e4d9a 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -243,7 +243,7 @@ export abstract class AbstractWorker< * @returns The names of the worker's task functions. */ public listTaskFunctions (): string[] { - return Array.from(this.taskFunctions.keys()) + return [...this.taskFunctions.keys()] } /** diff --git a/tests/worker/cluster-worker.test.js b/tests/worker/cluster-worker.test.js index 085e07a3..6bbf3246 100644 --- a/tests/worker/cluster-worker.test.js +++ b/tests/worker/cluster-worker.test.js @@ -3,7 +3,7 @@ const { ClusterWorker } = require('../../lib') describe('Cluster worker test suite', () => { let numberOfMessagesSent = 0 - const send = function () { + const send = () => { ++numberOfMessagesSent } class SpyWorker extends ClusterWorker { diff --git a/tests/worker/thread-worker.test.js b/tests/worker/thread-worker.test.js index 9eeaaa0a..072617d3 100644 --- a/tests/worker/thread-worker.test.js +++ b/tests/worker/thread-worker.test.js @@ -3,7 +3,7 @@ const { ThreadWorker } = require('../../lib') describe('Thread worker test suite', () => { let numberOfMessagesPosted = 0 - const postMessage = function () { + const postMessage = () => { ++numberOfMessagesPosted } class SpyWorker extends ThreadWorker {