From 041dc05b2a95b36db72525072ba54c4c58ffcf0e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 8 Sep 2023 14:00:32 +0200 Subject: [PATCH] fix: fix formatting issue. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .lintstagedrc.js | 4 +-- benchmarks/benchmarks-utils.mjs | 10 +++---- benchmarks/internal/bench.mjs | 4 +-- benchmarks/internal/cluster-worker.mjs | 2 +- benchmarks/internal/thread-worker.mjs | 2 +- .../dynamic-worker-nodes.js | 2 +- .../fixed-worker-nodes.js | 2 +- .../functions/function-to-bench.js | 2 +- biome.json | 8 ++++- examples/javascript/dynamicExample.js | 4 +-- examples/javascript/fixedExample.js | 4 +-- examples/javascript/multiFunctionExample.js | 10 +++---- .../typescript/http-client-pool/httpd-echo.js | 2 +- .../typescript/http-client-pool/src/worker.ts | 2 +- .../express-cluster/src/main.ts | 4 +-- .../express-cluster/src/worker.ts | 2 +- .../express-hybrid/src/express-worker.ts | 4 +-- .../express-hybrid/src/main.ts | 4 +-- .../src/request-handler-worker.ts | 2 +- .../express-worker_threads/src/main.ts | 4 +-- .../express-worker_threads/src/worker.ts | 2 +- .../fastify-cluster/src/main.ts | 4 +-- .../fastify-cluster/src/worker.ts | 6 ++-- .../fastify-hybrid/src/fastify-worker.ts | 4 +-- .../fastify-hybrid/src/main.ts | 4 +-- .../src/request-handler-worker.ts | 2 +- .../fastify-worker_threads/src/main.ts | 4 +-- .../fastify-worker_threads/src/worker.ts | 2 +- .../ws-cluster/requests.js | 2 +- .../ws-cluster/src/main.ts | 4 +-- .../ws-cluster/src/worker.ts | 4 +-- .../ws-hybrid/requests.js | 2 +- .../ws-hybrid/src/main.ts | 4 +-- .../ws-hybrid/src/request-handler-worker.ts | 2 +- .../ws-hybrid/src/websocket-server-worker.ts | 6 ++-- .../ws-worker_threads/requests.js | 2 +- .../ws-worker_threads/src/main.ts | 6 ++-- .../ws-worker_threads/src/worker.ts | 2 +- examples/typescript/worker.ts | 2 +- src/pools/abstract-pool.ts | 30 +++++++++---------- src/pools/cluster/fixed.ts | 2 +- src/pools/thread/fixed.ts | 6 ++-- src/pools/worker-node.ts | 2 +- src/utils.ts | 2 +- src/worker/abstract-worker.ts | 8 ++--- tests/pools/abstract/abstract-pool.test.js | 10 +++---- tests/pools/cluster/dynamic.test.js | 6 ++-- tests/pools/cluster/fixed.test.js | 18 +++++------ tests/pools/thread/dynamic.test.js | 6 ++-- tests/pools/thread/fixed.test.js | 18 +++++------ tests/test-utils.js | 16 +++++----- .../testMultipleTaskFunctionsWorker.js | 6 ++-- .../thread/testMultipleTaskFunctionsWorker.js | 6 ++-- typedoc.mjs | 2 +- 54 files changed, 143 insertions(+), 137 deletions(-) diff --git a/.lintstagedrc.js b/.lintstagedrc.js index ed9df14a..ed6da302 100644 --- a/.lintstagedrc.js +++ b/.lintstagedrc.js @@ -1,9 +1,9 @@ module.exports = { '**/*.{ts,tsx,js,jsx,cjs,mjs}': [ - 'biome format --write --no-errors-on-unmatched', + 'biome format --write', 'ts-standard --fix', 'eslint --cache --fix' ], - '!(.vscode/**)**/*.json': ['biome format --write --no-errors-on-unmatched'], + '**/*.json': ['biome format --write'], '**/*.{md,yml,yaml}': ['prettier --cache --write'] } diff --git a/benchmarks/benchmarks-utils.mjs b/benchmarks/benchmarks-utils.mjs index e8c67583..259fca56 100644 --- a/benchmarks/benchmarks-utils.mjs +++ b/benchmarks/benchmarks-utils.mjs @@ -23,7 +23,7 @@ export const runTest = async (pool, { taskExecutions, workerData }) => { } return null }) - .catch((err) => { + .catch(err => { console.error(err) return reject(err) }) @@ -46,7 +46,7 @@ export const generateRandomInteger = ( return Math.floor(Math.random() * (max + 1)) } -const jsonIntegerSerialization = (n) => { +const jsonIntegerSerialization = n => { for (let i = 0; i < n; i++) { const o = { a: i @@ -61,7 +61,7 @@ const jsonIntegerSerialization = (n) => { * @param {number} n - The number of fibonacci numbers to generate. * @returns {number} - The nth fibonacci number. */ -const fibonacci = (n) => { +const fibonacci = n => { if (n <= 1) return n return fibonacci(n - 1) + fibonacci(n - 2) } @@ -71,7 +71,7 @@ const fibonacci = (n) => { * @param {number} n - The number to calculate the factorial of. * @returns {number} - The factorial of n. */ -const factorial = (n) => { +const factorial = n => { if (n === 0) { return 1 } @@ -100,7 +100,7 @@ const readWriteFiles = ( return { ok: 1 } } -export const executeTaskFunction = (data) => { +export const executeTaskFunction = data => { switch (data.function) { case TaskFunctions.jsonIntegerSerialization: return jsonIntegerSerialization(data.taskSize || 1000) diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 193827f3..2749da42 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -50,7 +50,7 @@ const workerData = { function: TaskFunctions.jsonIntegerSerialization, taskSize: 1000 } -const addPools = (pools) => +const addPools = pools => pools.map(([name, pool]) => { return add(name, async () => { await runTest(pool, { @@ -90,4 +90,4 @@ suite( // eslint-disable-next-line n/no-process-exit return process.exit() }) - .catch((err) => console.error(err)) + .catch(err => console.error(err)) diff --git a/benchmarks/internal/cluster-worker.mjs b/benchmarks/internal/cluster-worker.mjs index fee9d3f8..f6b3b056 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 -const 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 f88cf076..94250a3a 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 -const taskFunction = (data) => { +const taskFunction = data => { data = data || {} data.function = data.function || TaskFunctions.jsonIntegerSerialization const res = executeTaskFunction(data) diff --git a/benchmarks/versus-external-pools/dynamic-worker-nodes.js b/benchmarks/versus-external-pools/dynamic-worker-nodes.js index cdac7274..74b113c3 100644 --- a/benchmarks/versus-external-pools/dynamic-worker-nodes.js +++ b/benchmarks/versus-external-pools/dynamic-worker-nodes.js @@ -28,7 +28,7 @@ async function run () { // eslint-disable-next-line n/no-process-exit process.exit() } -;(async () => { +(async () => { try { await run() } catch (e) { diff --git a/benchmarks/versus-external-pools/fixed-worker-nodes.js b/benchmarks/versus-external-pools/fixed-worker-nodes.js index 94008400..e65e9888 100644 --- a/benchmarks/versus-external-pools/fixed-worker-nodes.js +++ b/benchmarks/versus-external-pools/fixed-worker-nodes.js @@ -28,7 +28,7 @@ async function run () { // eslint-disable-next-line n/no-process-exit process.exit() } -;(async () => { +(async () => { try { await run() } catch (e) { diff --git a/benchmarks/versus-external-pools/functions/function-to-bench.js b/benchmarks/versus-external-pools/functions/function-to-bench.js index eca756b7..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. */ -const functionToBench = (data) => { +const functionToBench = data => { const crypto = require('crypto') const fs = require('fs') const TaskTypes = { diff --git a/biome.json b/biome.json index 55a5f761..f4963400 100644 --- a/biome.json +++ b/biome.json @@ -18,7 +18,13 @@ "formatter": { "quoteStyle": "single", "trailingComma": "none", - "semicolons": "asNeeded" + "semicolons": "asNeeded", + "arrowParentheses": "asNeeded" + } + }, + "json": { + "parser": { + "allowComments": true } }, "files": { diff --git a/examples/javascript/dynamicExample.js b/examples/javascript/dynamicExample.js index 34281709..33fdec97 100644 --- a/examples/javascript/dynamicExample.js +++ b/examples/javascript/dynamicExample.js @@ -10,7 +10,7 @@ const pool = new DynamicThreadPool( availableParallelism(), './yourWorker.js', { - errorHandler: (e) => console.error(e), + errorHandler: e => console.error(e), onlineHandler: () => console.info('worker is online') } ) @@ -37,5 +37,5 @@ for (let i = 1; i <= iterations; i++) { } return null }) - .catch((err) => console.error(err)) + .catch(err => console.error(err)) } diff --git a/examples/javascript/fixedExample.js b/examples/javascript/fixedExample.js index 99d1a5e1..66bfc8fc 100644 --- a/examples/javascript/fixedExample.js +++ b/examples/javascript/fixedExample.js @@ -6,7 +6,7 @@ const { } = require('poolifier') const pool = new FixedThreadPool(availableParallelism(), './yourWorker.js', { - errorHandler: (e) => console.error(e), + errorHandler: e => console.error(e), onlineHandler: () => console.info('worker is online') }) let poolReady = 0 @@ -29,5 +29,5 @@ for (let i = 1; i <= iterations; i++) { } return null }) - .catch((err) => console.error(err)) + .catch(err => console.error(err)) } diff --git a/examples/javascript/multiFunctionExample.js b/examples/javascript/multiFunctionExample.js index addbf46c..27a50325 100644 --- a/examples/javascript/multiFunctionExample.js +++ b/examples/javascript/multiFunctionExample.js @@ -5,18 +5,18 @@ const pool = new FixedThreadPool( availableParallelism(), './multiFunctionWorker.js', { - errorHandler: (e) => console.error(e), + errorHandler: e => console.error(e), onlineHandler: () => console.info('worker is online') } ) pool .execute({ text: 'hello' }, 'fn0') - .then((res) => console.info(res)) - .catch((err) => console.error(err)) + .then(res => console.info(res)) + .catch(err => console.error(err)) pool .execute({ text: 'multiple functions' }, 'fn1') - .then((res) => console.info(res)) - .catch((err) => console.error(err)) + .then(res => console.info(res)) + .catch(err => console.error(err)) setTimeout(pool.destroy(), 3000) diff --git a/examples/typescript/http-client-pool/httpd-echo.js b/examples/typescript/http-client-pool/httpd-echo.js index cbfb8da7..53b8ad11 100644 --- a/examples/typescript/http-client-pool/httpd-echo.js +++ b/examples/typescript/http-client-pool/httpd-echo.js @@ -7,7 +7,7 @@ server .on('request', (request, response) => { let body = [] request - .on('data', (chunk) => { + .on('data', chunk => { body.push(chunk) }) .on('end', () => { diff --git a/examples/typescript/http-client-pool/src/worker.ts b/examples/typescript/http-client-pool/src/worker.ts index d9298e3f..b7c59629 100644 --- a/examples/typescript/http-client-pool/src/worker.ts +++ b/examples/typescript/http-client-pool/src/worker.ts @@ -11,7 +11,7 @@ class HttpClientWorker extends ThreadWorker { super({ node_fetch: async (workerData?: WorkerData) => { const response = await nodeFetch( - (workerData as WorkerData).input, + (workerData as WorkerData).input as URL | NodeFetchRequestInfo, workerData?.init as NodeFetchRequestInit ) // The response is not structured-cloneable, so we return the response text body instead. diff --git a/examples/typescript/http-server-pool/express-cluster/src/main.ts b/examples/typescript/http-server-pool/express-cluster/src/main.ts index acbc9b7f..86560455 100644 --- a/examples/typescript/http-server-pool/express-cluster/src/main.ts +++ b/examples/typescript/http-server-pool/express-cluster/src/main.ts @@ -15,7 +15,7 @@ const pool = new FixedClusterPool( onlineHandler: () => { pool .execute({ port: 8080 }) - .then((response) => { + .then(response => { if (response.status) { console.info( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions @@ -24,7 +24,7 @@ const pool = new FixedClusterPool( } return null }) - .catch((error) => { + .catch(error => { console.error('Express failed to start in cluster worker:', error) }) }, diff --git a/examples/typescript/http-server-pool/express-cluster/src/worker.ts b/examples/typescript/http-server-pool/express-cluster/src/worker.ts index a2dbcefe..da1066c4 100644 --- a/examples/typescript/http-server-pool/express-cluster/src/worker.ts +++ b/examples/typescript/http-server-pool/express-cluster/src/worker.ts @@ -4,7 +4,7 @@ import { ClusterWorker } from 'poolifier' import express, { type Express, type Request, type Response } from 'express' import { type WorkerData, type WorkerResponse } from './types.js' -const factorial: (n: number) => number = (n) => { +const factorial: (n: number) => number = n => { if (n === 0) { return 1 } diff --git a/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts b/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts index c6174a99..db05cdbe 100644 --- a/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts +++ b/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts @@ -52,7 +52,7 @@ ClusterWorkerResponse application.all('/api/echo', (req: Request, res: Response) => { ExpressWorker.requestHandlerPool .execute({ data: req.body }, 'echo') - .then((response) => { + .then(response => { return res.send(response.data).end() }) .catch(emptyFunction) @@ -62,7 +62,7 @@ ClusterWorkerResponse const { number } = req.params ExpressWorker.requestHandlerPool .execute({ data: { number: parseInt(number) } }, 'factorial') - .then((response) => { + .then(response => { return res.send(response.data).end() }) .catch(emptyFunction) diff --git a/examples/typescript/http-server-pool/express-hybrid/src/main.ts b/examples/typescript/http-server-pool/express-hybrid/src/main.ts index 838c6e26..08563f4b 100644 --- a/examples/typescript/http-server-pool/express-hybrid/src/main.ts +++ b/examples/typescript/http-server-pool/express-hybrid/src/main.ts @@ -34,7 +34,7 @@ const pool = new FixedClusterPool( console.error('Thread worker error:', e) } }) - .then((response) => { + .then(response => { if (response.status) { console.info( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions @@ -43,7 +43,7 @@ const pool = new FixedClusterPool( } return null }) - .catch((error) => { + .catch(error => { console.error('Express failed to start in cluster worker:', error) }) }, diff --git a/examples/typescript/http-server-pool/express-hybrid/src/request-handler-worker.ts b/examples/typescript/http-server-pool/express-hybrid/src/request-handler-worker.ts index 6a88d20a..40cde50d 100644 --- a/examples/typescript/http-server-pool/express-hybrid/src/request-handler-worker.ts +++ b/examples/typescript/http-server-pool/express-hybrid/src/request-handler-worker.ts @@ -5,7 +5,7 @@ import { type ThreadWorkerResponse } from './types.js' -const factorial: (n: number) => number = (n) => { +const factorial: (n: number) => number = n => { if (n === 0) { return 1 } diff --git a/examples/typescript/http-server-pool/express-worker_threads/src/main.ts b/examples/typescript/http-server-pool/express-worker_threads/src/main.ts index 970cf4d0..4f1a4d95 100644 --- a/examples/typescript/http-server-pool/express-worker_threads/src/main.ts +++ b/examples/typescript/http-server-pool/express-worker_threads/src/main.ts @@ -21,7 +21,7 @@ expressApp.use(express.json()) expressApp.all('/api/echo', (req: Request, res: Response) => { requestHandlerPool .execute({ body: req.body }, 'echo') - .then((response) => { + .then(response => { return res.send(response.body).end() }) .catch(emptyFunction) @@ -31,7 +31,7 @@ expressApp.get('/api/factorial/:number', (req: Request, res: Response) => { const { number } = req.params requestHandlerPool .execute({ body: { number: parseInt(number) } }, 'factorial') - .then((response) => { + .then(response => { return res.send(response.body).end() }) .catch(emptyFunction) diff --git a/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts b/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts index cc46cba4..7589aa6b 100644 --- a/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts +++ b/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts @@ -5,7 +5,7 @@ import { type WorkerResponse } from './types.js' -const factorial: (n: number) => number = (n) => { +const factorial: (n: number) => number = n => { if (n === 0) { return 1 } diff --git a/examples/typescript/http-server-pool/fastify-cluster/src/main.ts b/examples/typescript/http-server-pool/fastify-cluster/src/main.ts index 1dc88be2..88167a3c 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/src/main.ts +++ b/examples/typescript/http-server-pool/fastify-cluster/src/main.ts @@ -15,7 +15,7 @@ const pool = new FixedClusterPool( onlineHandler: () => { pool .execute({ port: 8080 }) - .then((response) => { + .then(response => { if (response.status) { console.info( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions @@ -24,7 +24,7 @@ const pool = new FixedClusterPool( } return null }) - .catch((error) => { + .catch(error => { console.error('Fastify failed to start in cluster worker:', error) }) }, diff --git a/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts b/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts index 283a223e..ee64ee2e 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts +++ b/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts @@ -3,7 +3,7 @@ import { ClusterWorker } from 'poolifier' import Fastify, { type FastifyInstance } from 'fastify' import type { WorkerData, WorkerResponse } from './types.js' -const factorial: (n: number) => number = (n) => { +const factorial: (n: number) => number = n => { if (n === 0) { return 1 } @@ -22,13 +22,13 @@ class FastifyWorker extends ClusterWorker { logger: true }) - FastifyWorker.fastify.all('/api/echo', (request) => { + FastifyWorker.fastify.all('/api/echo', request => { return request.body }) FastifyWorker.fastify.get<{ Params: { number: number } - }>('/api/factorial/:number', (request) => { + }>('/api/factorial/:number', request => { const { number } = request.params return { number: factorial(number) } }) diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts index 0566ee01..388730dc 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts @@ -24,7 +24,7 @@ ClusterWorkerResponse fastifyPoolifierOptions ) - FastifyWorker.fastify.all('/api/echo', async (request) => { + FastifyWorker.fastify.all('/api/echo', async request => { return ( await FastifyWorker.fastify.execute({ data: request.body }, 'echo') ).data @@ -32,7 +32,7 @@ ClusterWorkerResponse FastifyWorker.fastify.get<{ Params: { number: number } - }>('/api/factorial/:number', async (request) => { + }>('/api/factorial/:number', async request => { const { number } = request.params return ( await FastifyWorker.fastify.execute({ data: { number } }, 'factorial') diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts index d840dfb9..66be31a8 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts @@ -34,7 +34,7 @@ const pool = new FixedClusterPool( console.error('Thread worker error', e) } }) - .then((response) => { + .then(response => { if (response.status) { console.info( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions @@ -43,7 +43,7 @@ const pool = new FixedClusterPool( } return null }) - .catch((error) => { + .catch(error => { console.error('Fastify failed to start in cluster worker:', error) }) }, diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts index 6a88d20a..40cde50d 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts @@ -5,7 +5,7 @@ import { type ThreadWorkerResponse } from './types.js' -const factorial: (n: number) => number = (n) => { +const factorial: (n: number) => number = n => { if (n === 0) { return 1 } diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts b/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts index f1271c6e..cc647a0f 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts @@ -28,13 +28,13 @@ await fastify.register(fastifyPoolifier, { } }) -fastify.all('/api/echo', async (request) => { +fastify.all('/api/echo', async request => { return (await fastify.execute({ body: request.body }, 'echo')).body }) fastify.get<{ Params: { number: number } -}>('/api/factorial/:number', async (request) => { +}>('/api/factorial/:number', async request => { const { number } = request.params return (await fastify.execute({ body: { number } }, 'factorial')).body }) diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts b/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts index cc46cba4..7589aa6b 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts @@ -5,7 +5,7 @@ import { type WorkerResponse } from './types.js' -const factorial: (n: number) => number = (n) => { +const factorial: (n: number) => number = n => { if (n === 0) { return 1 } diff --git a/examples/typescript/websocket-server-pool/ws-cluster/requests.js b/examples/typescript/websocket-server-pool/ws-cluster/requests.js index 3f796e36..1f302a6c 100644 --- a/examples/typescript/websocket-server-pool/ws-cluster/requests.js +++ b/examples/typescript/websocket-server-pool/ws-cluster/requests.js @@ -16,6 +16,6 @@ ws.on('open', () => { } }) -ws.on('message', (message) => { +ws.on('message', message => { console.info('message received: %s', message) }) diff --git a/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts b/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts index ebf35134..ad58bd20 100644 --- a/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts +++ b/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts @@ -15,7 +15,7 @@ const pool = new FixedClusterPool( onlineHandler: () => { pool .execute({ port: 8080 }) - .then((response) => { + .then(response => { if (response.status) { console.info( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions @@ -24,7 +24,7 @@ const pool = new FixedClusterPool( } return null }) - .catch((error) => { + .catch(error => { console.error( 'WebSocket server failed to start in cluster worker:', error diff --git a/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts b/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts index 143dc6db..5e758eb7 100644 --- a/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts +++ b/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts @@ -8,7 +8,7 @@ import { type WorkerResponse } from './types.js' -const factorial: (n: number) => number = (n) => { +const factorial: (n: number) => number = n => { if (n === 0) { return 1 } @@ -29,7 +29,7 @@ class WebSocketServerWorker extends ClusterWorker { ) }) - WebSocketServerWorker.wss.on('connection', (ws) => { + WebSocketServerWorker.wss.on('connection', ws => { ws.on('error', console.error) ws.on('message', (message: RawData) => { const { type, data } = JSON.parse( diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/requests.js b/examples/typescript/websocket-server-pool/ws-hybrid/requests.js index 3f796e36..1f302a6c 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/requests.js +++ b/examples/typescript/websocket-server-pool/ws-hybrid/requests.js @@ -16,6 +16,6 @@ ws.on('open', () => { } }) -ws.on('message', (message) => { +ws.on('message', message => { console.info('message received: %s', message) }) diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts index 5cfbbf43..f6536bd0 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts @@ -34,7 +34,7 @@ const pool = new FixedClusterPool( console.error('Thread worker error:', e) } }) - .then((response) => { + .then(response => { if (response.status) { console.info( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions @@ -43,7 +43,7 @@ const pool = new FixedClusterPool( } return null }) - .catch((error) => { + .catch(error => { console.error( 'WebSocket server failed to start in cluster worker:', error diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts index 6a88d20a..40cde50d 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts @@ -5,7 +5,7 @@ import { type ThreadWorkerResponse } from './types.js' -const factorial: (n: number) => number = (n) => { +const factorial: (n: number) => number = n => { if (n === 0) { return 1 } diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts index 2a2c4502..ec6a3d18 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts @@ -50,7 +50,7 @@ ClusterWorkerResponse ) }) - WebSocketServerWorker.wss.on('connection', (ws) => { + WebSocketServerWorker.wss.on('connection', ws => { ws.on('error', console.error) ws.on('message', (message: RawData) => { const { type, data } = JSON.parse( @@ -61,7 +61,7 @@ ClusterWorkerResponse case MessageType.echo: WebSocketServerWorker.requestHandlerPool .execute({ data }, 'echo') - .then((response) => { + .then(response => { ws.send( JSON.stringify({ type: MessageType.echo, @@ -75,7 +75,7 @@ ClusterWorkerResponse case MessageType.factorial: WebSocketServerWorker.requestHandlerPool .execute({ data }, 'factorial') - .then((response) => { + .then(response => { ws.send( JSON.stringify({ type: MessageType.factorial, diff --git a/examples/typescript/websocket-server-pool/ws-worker_threads/requests.js b/examples/typescript/websocket-server-pool/ws-worker_threads/requests.js index 3f796e36..1f302a6c 100644 --- a/examples/typescript/websocket-server-pool/ws-worker_threads/requests.js +++ b/examples/typescript/websocket-server-pool/ws-worker_threads/requests.js @@ -16,6 +16,6 @@ ws.on('open', () => { } }) -ws.on('message', (message) => { +ws.on('message', message => { console.info('message received: %s', message) }) diff --git a/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts b/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts index 0c1acba1..c8478366 100644 --- a/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts +++ b/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts @@ -13,7 +13,7 @@ const emptyFunction = (): void => { /* Intentional */ } -wss.on('connection', (ws) => { +wss.on('connection', ws => { ws.on('error', console.error) ws.on('message', (message: RawData) => { const { type, data } = JSON.parse( @@ -24,7 +24,7 @@ wss.on('connection', (ws) => { case MessageType.echo: requestHandlerPool .execute({ data }, 'echo') - .then((response) => { + .then(response => { ws.send( JSON.stringify({ type: MessageType.echo, @@ -38,7 +38,7 @@ wss.on('connection', (ws) => { case MessageType.factorial: requestHandlerPool .execute({ data }, 'factorial') - .then((response) => { + .then(response => { ws.send( JSON.stringify({ type: MessageType.factorial, diff --git a/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts b/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts index e31cc4fe..92b9d64a 100644 --- a/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts +++ b/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts @@ -5,7 +5,7 @@ import { type WorkerResponse } from './types.js' -const factorial: (n: number) => number = (n) => { +const factorial: (n: number) => number = n => { if (n === 0) { return 1 } diff --git a/examples/typescript/worker.ts b/examples/typescript/worker.ts index caf6e3ac..81d39df3 100644 --- a/examples/typescript/worker.ts +++ b/examples/typescript/worker.ts @@ -18,7 +18,7 @@ class MyThreadWorker extends ThreadWorker> { } private async process (data: MyData): Promise { - return await new Promise((resolve) => { + return await new Promise(resolve => { setTimeout(() => { resolve({ message: 'Hello from Worker :)', data }) }, 10000) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 9dcc6edd..fea2e3a1 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -418,14 +418,14 @@ export abstract class AbstractPool< minimum: round( min( ...this.workerNodes.map( - (workerNode) => workerNode.usage.runTime?.minimum ?? Infinity + workerNode => workerNode.usage.runTime?.minimum ?? Infinity ) ) ), maximum: round( max( ...this.workerNodes.map( - (workerNode) => workerNode.usage.runTime?.maximum ?? -Infinity + workerNode => workerNode.usage.runTime?.maximum ?? -Infinity ) ) ), @@ -461,14 +461,14 @@ export abstract class AbstractPool< minimum: round( min( ...this.workerNodes.map( - (workerNode) => workerNode.usage.waitTime?.minimum ?? Infinity + workerNode => workerNode.usage.waitTime?.minimum ?? Infinity ) ) ), maximum: round( max( ...this.workerNodes.map( - (workerNode) => workerNode.usage.waitTime?.maximum ?? -Infinity + workerNode => workerNode.usage.waitTime?.maximum ?? -Infinity ) ) ), @@ -590,7 +590,7 @@ export abstract class AbstractPool< */ private getWorkerNodeKeyByWorker (worker: Worker): number { return this.workerNodes.findIndex( - (workerNode) => workerNode.worker === worker + workerNode => workerNode.worker === worker ) } @@ -602,7 +602,7 @@ export abstract class AbstractPool< */ private getWorkerNodeKeyByWorkerId (workerId: number): number { return this.workerNodes.findIndex( - (workerNode) => workerNode.info.id === workerId + workerNode => workerNode.info.id === workerId ) } @@ -706,7 +706,7 @@ export abstract class AbstractPool< if (this.opts.enableTasksQueue === true) { return ( this.workerNodes.findIndex( - (workerNode) => + workerNode => workerNode.info.ready && workerNode.usage.tasks.executing < (this.opts.tasksQueueOptions?.concurrency as number) @@ -715,7 +715,7 @@ export abstract class AbstractPool< } else { return ( this.workerNodes.findIndex( - (workerNode) => + workerNode => workerNode.info.ready && workerNode.usage.tasks.executing === 0 ) === -1 ) @@ -815,7 +815,7 @@ export abstract class AbstractPool< workerId: number ): Promise { await new Promise((resolve, reject) => { - this.registerWorkerMessageListener(workerNodeKey, (message) => { + this.registerWorkerMessageListener(workerNodeKey, message => { if (message.kill === 'success') { resolve() } else if (message.kill === 'failure') { @@ -1064,7 +1064,7 @@ export abstract class AbstractPool< worker.on('online', this.opts.onlineHandler ?? EMPTY_FUNCTION) worker.on('message', this.opts.messageHandler ?? EMPTY_FUNCTION) worker.on('error', this.opts.errorHandler ?? EMPTY_FUNCTION) - worker.on('error', (error) => { + worker.on('error', error => { const workerNodeKey = this.getWorkerNodeKeyByWorker(worker) const workerInfo = this.getWorkerInfo(workerNodeKey) workerInfo.ready = false @@ -1104,7 +1104,7 @@ export abstract class AbstractPool< */ protected createAndSetupDynamicWorkerNode (): number { const workerNodeKey = this.createAndSetupWorkerNode() - this.registerWorkerMessageListener(workerNodeKey, (message) => { + this.registerWorkerMessageListener(workerNodeKey, message => { const localWorkerNodeKey = this.getWorkerNodeKeyByWorkerId( message.workerId ) @@ -1119,7 +1119,7 @@ export abstract class AbstractPool< workerUsage.tasks.executing === 0 && this.tasksQueueSize(localWorkerNodeKey) === 0))) ) { - this.destroyWorkerNode(localWorkerNodeKey).catch((error) => { + this.destroyWorkerNode(localWorkerNodeKey).catch(error => { this.emitter?.emit(PoolEvents.error, error) }) } @@ -1253,7 +1253,7 @@ export abstract class AbstractPool< workerNodeB.usage.tasks.queued - workerNodeA.usage.tasks.queued ) const sourceWorkerNode = workerNodes.find( - (workerNode) => + workerNode => workerNode.info.ready && workerNode.info.id !== workerId && workerNode.usage.tasks.queued > 0 @@ -1319,7 +1319,7 @@ export abstract class AbstractPool< * @returns The listener function to execute when a message is received from a worker. */ protected workerListener (): (message: MessageValue) => void { - return (message) => { + return message => { this.checkMessageWorkerId(message) if (message.ready != null && message.taskFunctions != null) { // Worker ready response received from worker @@ -1457,7 +1457,7 @@ export abstract class AbstractPool< return ( this.opts.enableTasksQueue === true && this.workerNodes.findIndex( - (workerNode) => !workerNode.hasBackPressure() + workerNode => !workerNode.hasBackPressure() ) === -1 ) } diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index 75c08535..17ef7e9e 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -65,7 +65,7 @@ export class FixedClusterPool< // FIXME: wait for tasks to be finished const workerNode = this.workerNodes[workerNodeKey] const worker = workerNode.worker - const waitWorkerExit = new Promise((resolve) => { + const waitWorkerExit = new Promise(resolve => { worker.on('exit', () => { resolve() }) diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index 9acfd640..6e234e2e 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -62,7 +62,7 @@ export class FixedThreadPool< // FIXME: wait for tasks to be finished const workerNode = this.workerNodes[workerNodeKey] const worker = workerNode.worker - const waitWorkerExit = new Promise((resolve) => { + const waitWorkerExit = new Promise(resolve => { worker.on('exit', () => { resolve() }) @@ -82,7 +82,7 @@ export class FixedThreadPool< message: MessageValue, transferList?: TransferListItem[] ): void { - ;( + ( this.workerNodes[workerNodeKey].messageChannel as MessageChannel ).port1.postMessage(message, transferList) } @@ -108,7 +108,7 @@ export class FixedThreadPool< workerNodeKey: number, listener: (message: MessageValue) => void ): void { - ;( + ( this.workerNodes[workerNodeKey].messageChannel as MessageChannel ).port1.on('message', listener) } diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index dd116dfb..ca275ded 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -169,7 +169,7 @@ implements IWorkerNode { this.onEmptyQueueCount = 0 return } - ;(this.onEmptyQueue as WorkerNodeEventCallback)(this.info.id as number) + (this.onEmptyQueue as WorkerNodeEventCallback)(this.info.id as number) ++this.onEmptyQueueCount await sleep(exponentialDelay(this.onEmptyQueueCount)) await this.startOnEmptyQueue() diff --git a/src/utils.ts b/src/utils.ts index 86b6edad..400a92b1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -104,7 +104,7 @@ export const getWorkerId = (worker: IWorker): number | undefined => { * @internal */ export const sleep = async (ms: number): Promise => { - await new Promise((resolve) => { + await new Promise(resolve => { setTimeout(resolve, ms) }) } diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index a0d78dbd..5b3c3a3f 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -268,7 +268,7 @@ export abstract class AbstractWorker< names[names.indexOf(DEFAULT_TASK_NAME)], defaultTaskFunctionName, ...names.filter( - (name) => name !== DEFAULT_TASK_NAME && name !== defaultTaskFunctionName + name => name !== DEFAULT_TASK_NAME && name !== defaultTaskFunctionName ) ] } @@ -351,7 +351,7 @@ export abstract class AbstractWorker< protected handleKillMessage (message: MessageValue): void { this.stopCheckActive() if (isAsyncFunction(this.opts.killHandler)) { - ;(this.opts.killHandler?.() as Promise) + (this.opts.killHandler?.() as Promise) .then(() => { this.sendToMainWorker({ kill: 'success', workerId: this.id }) return null @@ -545,7 +545,7 @@ export abstract class AbstractWorker< const { name, taskId, data } = task let taskPerformance = this.beginTaskPerformance(name) fn(data) - .then((res) => { + .then(res => { taskPerformance = this.endTaskPerformance(taskPerformance) this.sendToMainWorker({ data: res, @@ -555,7 +555,7 @@ export abstract class AbstractWorker< }) return null }) - .catch((e) => { + .catch(e => { const errorMessage = this.handleError(e as Error | string) this.sendToMainWorker({ taskError: { diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 2a6ba858..a206948f 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -36,7 +36,7 @@ describe('Abstract pool test suite', () => { numberOfWorkers, './tests/worker-files/thread/testWorker.js', { - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) ).toThrowError( @@ -1028,7 +1028,7 @@ describe('Abstract pool test suite', () => { ) let poolInfo let poolReady = 0 - pool.emitter.on(PoolEvents.ready, (info) => { + pool.emitter.on(PoolEvents.ready, info => { ++poolReady poolInfo = info }) @@ -1060,7 +1060,7 @@ describe('Abstract pool test suite', () => { const promises = new Set() let poolBusy = 0 let poolInfo - pool.emitter.on(PoolEvents.busy, (info) => { + pool.emitter.on(PoolEvents.busy, info => { ++poolBusy poolInfo = info }) @@ -1098,7 +1098,7 @@ describe('Abstract pool test suite', () => { const promises = new Set() let poolFull = 0 let poolInfo - pool.emitter.on(PoolEvents.full, (info) => { + pool.emitter.on(PoolEvents.full, info => { ++poolFull poolInfo = info }) @@ -1137,7 +1137,7 @@ describe('Abstract pool test suite', () => { const promises = new Set() let poolBackPressure = 0 let poolInfo - pool.emitter.on(PoolEvents.backPressure, (info) => { + pool.emitter.on(PoolEvents.backPressure, info => { ++poolBackPressure poolInfo = info }) diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index 8f4d2c9a..a2b275fd 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -11,7 +11,7 @@ describe('Dynamic cluster pool test suite', () => { max, './tests/worker-files/cluster/testWorker.js', { - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) @@ -91,7 +91,7 @@ describe('Dynamic cluster pool test suite', () => { max, './tests/worker-files/cluster/longRunningWorkerHardBehavior.js', { - errorHandler: (e) => console.error(e), + errorHandler: e => console.error(e), onlineHandler: () => console.info('long executing worker is online'), exitHandler: () => console.info('long executing worker exited') } @@ -118,7 +118,7 @@ describe('Dynamic cluster pool test suite', () => { max, './tests/worker-files/cluster/longRunningWorkerSoftBehavior.js', { - errorHandler: (e) => console.error(e), + errorHandler: e => console.error(e), onlineHandler: () => console.info('long executing worker is online'), exitHandler: () => console.info('long executing worker exited') } diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index af3bc452..9ee37ad8 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -11,7 +11,7 @@ describe('Fixed cluster pool test suite', () => { numberOfWorkers, './tests/worker-files/cluster/testWorker.js', { - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) const queuePool = new FixedClusterPool( @@ -22,7 +22,7 @@ describe('Fixed cluster pool test suite', () => { tasksQueueOptions: { concurrency: tasksConcurrency }, - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) const emptyPool = new FixedClusterPool( @@ -38,14 +38,14 @@ describe('Fixed cluster pool test suite', () => { numberOfWorkers, './tests/worker-files/cluster/errorWorker.js', { - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) const asyncErrorPool = new FixedClusterPool( numberOfWorkers, './tests/worker-files/cluster/asyncErrorWorker.js', { - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) const asyncPool = new FixedClusterPool( @@ -84,7 +84,7 @@ describe('Fixed cluster pool test suite', () => { numberOfWorkers, './tests/worker-files/cluster/testWorker.js', { - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) let poolReady = 0 @@ -180,7 +180,7 @@ describe('Fixed cluster pool test suite', () => { it('Verify that error handling is working properly:sync', async () => { const data = { f: 10 } let taskError - errorPool.emitter.on(PoolEvents.taskError, (e) => { + errorPool.emitter.on(PoolEvents.taskError, e => { taskError = e }) let inError @@ -199,7 +199,7 @@ describe('Fixed cluster pool test suite', () => { }) expect( errorPool.workerNodes.some( - (workerNode) => workerNode.usage.tasks.failed === 1 + workerNode => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) @@ -207,7 +207,7 @@ describe('Fixed cluster pool test suite', () => { it('Verify that error handling is working properly:async', async () => { const data = { f: 10 } let taskError - asyncErrorPool.emitter.on(PoolEvents.taskError, (e) => { + asyncErrorPool.emitter.on(PoolEvents.taskError, e => { taskError = e }) let inError @@ -226,7 +226,7 @@ describe('Fixed cluster pool test suite', () => { }) expect( asyncErrorPool.workerNodes.some( - (workerNode) => workerNode.usage.tasks.failed === 1 + workerNode => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index e30099dd..0eab0381 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -11,7 +11,7 @@ describe('Dynamic thread pool test suite', () => { max, './tests/worker-files/thread/testWorker.js', { - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) @@ -91,7 +91,7 @@ describe('Dynamic thread pool test suite', () => { max, './tests/worker-files/thread/longRunningWorkerHardBehavior.js', { - errorHandler: (e) => console.error(e), + errorHandler: e => console.error(e), onlineHandler: () => console.info('long executing worker is online'), exitHandler: () => console.info('long executing worker exited') } @@ -118,7 +118,7 @@ describe('Dynamic thread pool test suite', () => { max, './tests/worker-files/thread/longRunningWorkerSoftBehavior.js', { - errorHandler: (e) => console.error(e), + errorHandler: e => console.error(e), onlineHandler: () => console.info('long executing worker is online'), exitHandler: () => console.info('long executing worker exited') } diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 901c6665..84871e73 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -11,7 +11,7 @@ describe('Fixed thread pool test suite', () => { numberOfThreads, './tests/worker-files/thread/testWorker.js', { - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) const queuePool = new FixedThreadPool( @@ -22,7 +22,7 @@ describe('Fixed thread pool test suite', () => { tasksQueueOptions: { concurrency: tasksConcurrency }, - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) const emptyPool = new FixedThreadPool( @@ -38,14 +38,14 @@ describe('Fixed thread pool test suite', () => { numberOfThreads, './tests/worker-files/thread/errorWorker.js', { - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) const asyncErrorPool = new FixedThreadPool( numberOfThreads, './tests/worker-files/thread/asyncErrorWorker.js', { - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) const asyncPool = new FixedThreadPool( @@ -84,7 +84,7 @@ describe('Fixed thread pool test suite', () => { numberOfThreads, './tests/worker-files/thread/testWorker.js', { - errorHandler: (e) => console.error(e) + errorHandler: e => console.error(e) } ) let poolReady = 0 @@ -206,7 +206,7 @@ describe('Fixed thread pool test suite', () => { it('Verify that error handling is working properly:sync', async () => { const data = { f: 10 } let taskError - errorPool.emitter.on(PoolEvents.taskError, (e) => { + errorPool.emitter.on(PoolEvents.taskError, e => { taskError = e }) let inError @@ -227,7 +227,7 @@ describe('Fixed thread pool test suite', () => { }) expect( errorPool.workerNodes.some( - (workerNode) => workerNode.usage.tasks.failed === 1 + workerNode => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) @@ -235,7 +235,7 @@ describe('Fixed thread pool test suite', () => { it('Verify that error handling is working properly:async', async () => { const data = { f: 10 } let taskError - asyncErrorPool.emitter.on(PoolEvents.taskError, (e) => { + asyncErrorPool.emitter.on(PoolEvents.taskError, e => { taskError = e }) let inError @@ -256,7 +256,7 @@ describe('Fixed thread pool test suite', () => { }) expect( asyncErrorPool.workerNodes.some( - (workerNode) => workerNode.usage.tasks.failed === 1 + workerNode => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) diff --git a/tests/test-utils.js b/tests/test-utils.js index 3234a6a2..b55f7621 100644 --- a/tests/test-utils.js +++ b/tests/test-utils.js @@ -1,7 +1,7 @@ const { TaskFunctions } = require('./test-types') const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => { - return new Promise((resolve) => { + return new Promise(resolve => { let events = 0 if (numberOfEventsToWait === 0) { resolve(events) @@ -18,7 +18,7 @@ const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => { } const waitPoolEvents = async (pool, poolEvent, numberOfEventsToWait) => { - return new Promise((resolve) => { + return new Promise(resolve => { let events = 0 if (numberOfEventsToWait === 0) { resolve(events) @@ -32,8 +32,8 @@ const waitPoolEvents = async (pool, poolEvent, numberOfEventsToWait) => { }) } -const sleep = async (ms) => { - return new Promise((resolve) => setTimeout(resolve, ms)) +const sleep = async ms => { + return new Promise(resolve => setTimeout(resolve, ms)) } const sleepTaskFunction = async ( @@ -65,7 +65,7 @@ const generateRandomInteger = (max = Number.MAX_SAFE_INTEGER, min = 0) => { return Math.floor(Math.random() * (max + 1)) } -const jsonIntegerSerialization = (n) => { +const jsonIntegerSerialization = n => { for (let i = 0; i < n; i++) { const o = { a: i @@ -80,7 +80,7 @@ const jsonIntegerSerialization = (n) => { * @param {number} n - The number of fibonacci numbers to generate. * @returns {number} - The nth fibonacci number. */ -const fibonacci = (n) => { +const fibonacci = n => { if (n <= 1) return n return fibonacci(n - 1) + fibonacci(n - 2) } @@ -90,14 +90,14 @@ const fibonacci = (n) => { * @param {number} n - The number to calculate the factorial of. * @returns {number} - The factorial of n. */ -const factorial = (n) => { +const factorial = n => { if (n === 0) { return 1 } return factorial(n - 1) * n } -const executeTaskFunction = (data) => { +const executeTaskFunction = data => { switch (data.function) { case TaskFunctions.jsonIntegerSerialization: return jsonIntegerSerialization(data.n || 100) diff --git a/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js b/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js index 2bb525e2..aecd5bbf 100644 --- a/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js +++ b/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js @@ -8,9 +8,9 @@ const { module.exports = new ClusterWorker( { - jsonIntegerSerialization: (data) => jsonIntegerSerialization(data.n), - factorial: (data) => factorial(data.n), - fibonacci: (data) => fibonacci(data.n) + jsonIntegerSerialization: data => jsonIntegerSerialization(data.n), + factorial: data => factorial(data.n), + fibonacci: data => fibonacci(data.n) }, { killBehavior: KillBehaviors.HARD, diff --git a/tests/worker-files/thread/testMultipleTaskFunctionsWorker.js b/tests/worker-files/thread/testMultipleTaskFunctionsWorker.js index 188c8e53..3fb6d758 100644 --- a/tests/worker-files/thread/testMultipleTaskFunctionsWorker.js +++ b/tests/worker-files/thread/testMultipleTaskFunctionsWorker.js @@ -8,9 +8,9 @@ const { module.exports = new ThreadWorker( { - jsonIntegerSerialization: (data) => jsonIntegerSerialization(data.n), - factorial: (data) => factorial(data.n), - fibonacci: (data) => fibonacci(data.n) + jsonIntegerSerialization: data => jsonIntegerSerialization(data.n), + factorial: data => factorial(data.n), + fibonacci: data => fibonacci(data.n) }, { killBehavior: KillBehaviors.HARD, diff --git a/typedoc.mjs b/typedoc.mjs index 1d74fb4e..b9f9cc99 100644 --- a/typedoc.mjs +++ b/typedoc.mjs @@ -9,7 +9,7 @@ try { }) const markdownFiles = readdirSync( join(dirname(fileURLToPath(import.meta.url)), 'docs') - ).filter((file) => file.endsWith('.md')) + ).filter(file => file.endsWith('.md')) for (const markdownFile of markdownFiles) { copyFileSync( join(dirname(fileURLToPath(import.meta.url)), 'docs', markdownFile), -- 2.34.1