From 440dd7d77da6e027b3b9543504addcf805f76c1d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 2 Aug 2023 15:16:12 +0200 Subject: [PATCH 1/1] refactor: code cleanups MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- benchmarks/internal/cluster-worker.mjs | 2 +- benchmarks/internal/thread-worker.mjs | 2 +- .../versus-external-pools/functions/function-to-bench.js | 4 +++- .../workers/workerpool/function-to-bench-worker.mjs | 4 ++-- src/worker/abstract-worker.ts | 2 +- tests/worker/cluster-worker.test.js | 2 +- tests/worker/thread-worker.test.js | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) 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 { -- 2.34.1