refactor: code cleanups
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 2 Aug 2023 13:16:12 +0000 (15:16 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 2 Aug 2023 13:16:12 +0000 (15:16 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
benchmarks/internal/cluster-worker.mjs
benchmarks/internal/thread-worker.mjs
benchmarks/versus-external-pools/functions/function-to-bench.js
benchmarks/versus-external-pools/workers/workerpool/function-to-bench-worker.mjs
src/worker/abstract-worker.ts
tests/worker/cluster-worker.test.js
tests/worker/thread-worker.test.js

index efbcf7b1cfd0bbf60c126f8f5af716b3c6a7dd45..60876bebef04bf97e3a866209fe65792bf6d985f 100644 (file)
@@ -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)
index e56eaa4cbcbb7cb0844439d3efd489278be15755..869e95f4ba6b070228800b9db00fa93e073b4e6d 100644 (file)
@@ -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)
index 5c63c794df69f26a61c12c8c04e8e3a18b0805ab..ecc39a1c92be59327bd6b7d9d141c8bbf485b4be 100644 (file)
@@ -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
index c49013c3efd19eaa78618d3d41086b246a384a4b..8515b1dc5ad8fe0aa4abc735e6450adabae28ba1 100644 (file)
@@ -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
 })
index 1b34fb139dd7d0d6513a298be184c5c342d8bcef..381e4d9a7357ec70ed425fa4ab9d3ae990a775a7 100644 (file)
@@ -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()]
   }
 
   /**
index 085e07a34e517e963b1e9a39cea56bb49f4d7cd9..6bbf3246f0b806b37d1165a7a719b216511bb027 100644 (file)
@@ -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 {
index 9eeaaa0a70d44eeced4d4ecc4fa88f885b426156..072617d35a4e47d3e1c7c0912b754e2afe4bb0cc 100644 (file)
@@ -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 {