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']
}
}
return null
})
- .catch((err) => {
+ .catch(err => {
console.error(err)
return reject(err)
})
return Math.floor(Math.random() * (max + 1))
}
-const jsonIntegerSerialization = (n) => {
+const jsonIntegerSerialization = n => {
for (let i = 0; i < n; i++) {
const o = {
a: i
* @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)
}
* @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 { ok: 1 }
}
-export const executeTaskFunction = (data) => {
+export const executeTaskFunction = data => {
switch (data.function) {
case TaskFunctions.jsonIntegerSerialization:
return jsonIntegerSerialization(data.taskSize || 1000)
function: TaskFunctions.jsonIntegerSerialization,
taskSize: 1000
}
-const addPools = (pools) =>
+const addPools = pools =>
pools.map(([name, pool]) => {
return add(name, async () => {
await runTest(pool, {
// eslint-disable-next-line n/no-process-exit
return process.exit()
})
- .catch((err) => console.error(err))
+ .catch(err => console.error(err))
const debug = false
-const taskFunction = (data) => {
+const taskFunction = data => {
data = data || {}
data.function = data.function || TaskFunctions.jsonIntegerSerialization
const res = executeTaskFunction(data)
const debug = false
-const taskFunction = (data) => {
+const taskFunction = data => {
data = data || {}
data.function = data.function || TaskFunctions.jsonIntegerSerialization
const res = executeTaskFunction(data)
// eslint-disable-next-line n/no-process-exit
process.exit()
}
-;(async () => {
+(async () => {
try {
await run()
} catch (e) {
// eslint-disable-next-line n/no-process-exit
process.exit()
}
-;(async () => {
+(async () => {
try {
await run()
} catch (e) {
* @param {*} data The worker data.
* @returns {*} The result.
*/
-const functionToBench = (data) => {
+const functionToBench = data => {
const crypto = require('crypto')
const fs = require('fs')
const TaskTypes = {
"formatter": {
"quoteStyle": "single",
"trailingComma": "none",
- "semicolons": "asNeeded"
+ "semicolons": "asNeeded",
+ "arrowParentheses": "asNeeded"
+ }
+ },
+ "json": {
+ "parser": {
+ "allowComments": true
}
},
"files": {
availableParallelism(),
'./yourWorker.js',
{
- errorHandler: (e) => console.error(e),
+ errorHandler: e => console.error(e),
onlineHandler: () => console.info('worker is online')
}
)
}
return null
})
- .catch((err) => console.error(err))
+ .catch(err => console.error(err))
}
} = 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
}
return null
})
- .catch((err) => console.error(err))
+ .catch(err => console.error(err))
}
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)
.on('request', (request, response) => {
let body = []
request
- .on('data', (chunk) => {
+ .on('data', chunk => {
body.push(chunk)
})
.on('end', () => {
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.
onlineHandler: () => {
pool
.execute({ port: 8080 })
- .then((response) => {
+ .then(response => {
if (response.status) {
console.info(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
}
return null
})
- .catch((error) => {
+ .catch(error => {
console.error('Express failed to start in cluster worker:', error)
})
},
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
}
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)
const { number } = req.params
ExpressWorker.requestHandlerPool
.execute({ data: { number: parseInt(number) } }, 'factorial')
- .then((response) => {
+ .then(response => {
return res.send(response.data).end()
})
.catch(emptyFunction)
console.error('Thread worker error:', e)
}
})
- .then((response) => {
+ .then(response => {
if (response.status) {
console.info(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
}
return null
})
- .catch((error) => {
+ .catch(error => {
console.error('Express failed to start in cluster worker:', error)
})
},
type ThreadWorkerResponse
} from './types.js'
-const factorial: (n: number) => number = (n) => {
+const factorial: (n: number) => number = n => {
if (n === 0) {
return 1
}
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)
const { number } = req.params
requestHandlerPool
.execute({ body: { number: parseInt(number) } }, 'factorial')
- .then((response) => {
+ .then(response => {
return res.send(response.body).end()
})
.catch(emptyFunction)
type WorkerResponse
} from './types.js'
-const factorial: (n: number) => number = (n) => {
+const factorial: (n: number) => number = n => {
if (n === 0) {
return 1
}
onlineHandler: () => {
pool
.execute({ port: 8080 })
- .then((response) => {
+ .then(response => {
if (response.status) {
console.info(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
}
return null
})
- .catch((error) => {
+ .catch(error => {
console.error('Fastify failed to start in cluster worker:', error)
})
},
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
}
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) }
})
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
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')
console.error('Thread worker error', e)
}
})
- .then((response) => {
+ .then(response => {
if (response.status) {
console.info(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
}
return null
})
- .catch((error) => {
+ .catch(error => {
console.error('Fastify failed to start in cluster worker:', error)
})
},
type ThreadWorkerResponse
} from './types.js'
-const factorial: (n: number) => number = (n) => {
+const factorial: (n: number) => number = n => {
if (n === 0) {
return 1
}
}
})
-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
})
type WorkerResponse
} from './types.js'
-const factorial: (n: number) => number = (n) => {
+const factorial: (n: number) => number = n => {
if (n === 0) {
return 1
}
}
})
-ws.on('message', (message) => {
+ws.on('message', message => {
console.info('message received: %s', message)
})
onlineHandler: () => {
pool
.execute({ port: 8080 })
- .then((response) => {
+ .then(response => {
if (response.status) {
console.info(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
}
return null
})
- .catch((error) => {
+ .catch(error => {
console.error(
'WebSocket server failed to start in cluster worker:',
error
type WorkerResponse
} from './types.js'
-const factorial: (n: number) => number = (n) => {
+const factorial: (n: number) => number = n => {
if (n === 0) {
return 1
}
)
})
- 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(
}
})
-ws.on('message', (message) => {
+ws.on('message', message => {
console.info('message received: %s', message)
})
console.error('Thread worker error:', e)
}
})
- .then((response) => {
+ .then(response => {
if (response.status) {
console.info(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
}
return null
})
- .catch((error) => {
+ .catch(error => {
console.error(
'WebSocket server failed to start in cluster worker:',
error
type ThreadWorkerResponse
} from './types.js'
-const factorial: (n: number) => number = (n) => {
+const factorial: (n: number) => number = n => {
if (n === 0) {
return 1
}
)
})
- 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(
case MessageType.echo:
WebSocketServerWorker.requestHandlerPool
.execute({ data }, 'echo')
- .then((response) => {
+ .then(response => {
ws.send(
JSON.stringify({
type: MessageType.echo,
case MessageType.factorial:
WebSocketServerWorker.requestHandlerPool
.execute({ data }, 'factorial')
- .then((response) => {
+ .then(response => {
ws.send(
JSON.stringify({
type: MessageType.factorial,
}
})
-ws.on('message', (message) => {
+ws.on('message', message => {
console.info('message received: %s', message)
})
/* Intentional */
}
-wss.on('connection', (ws) => {
+wss.on('connection', ws => {
ws.on('error', console.error)
ws.on('message', (message: RawData) => {
const { type, data } = JSON.parse(
case MessageType.echo:
requestHandlerPool
.execute({ data }, 'echo')
- .then((response) => {
+ .then(response => {
ws.send(
JSON.stringify({
type: MessageType.echo,
case MessageType.factorial:
requestHandlerPool
.execute({ data }, 'factorial')
- .then((response) => {
+ .then(response => {
ws.send(
JSON.stringify({
type: MessageType.factorial,
type WorkerResponse
} from './types.js'
-const factorial: (n: number) => number = (n) => {
+const factorial: (n: number) => number = n => {
if (n === 0) {
return 1
}
}
private async process (data: MyData): Promise<MyResponse> {
- return await new Promise((resolve) => {
+ return await new Promise(resolve => {
setTimeout(() => {
resolve({ message: 'Hello from Worker :)', data })
}, 10000)
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
)
)
),
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
)
)
),
*/
private getWorkerNodeKeyByWorker (worker: Worker): number {
return this.workerNodes.findIndex(
- (workerNode) => workerNode.worker === worker
+ workerNode => workerNode.worker === worker
)
}
*/
private getWorkerNodeKeyByWorkerId (workerId: number): number {
return this.workerNodes.findIndex(
- (workerNode) => workerNode.info.id === workerId
+ workerNode => workerNode.info.id === workerId
)
}
if (this.opts.enableTasksQueue === true) {
return (
this.workerNodes.findIndex(
- (workerNode) =>
+ workerNode =>
workerNode.info.ready &&
workerNode.usage.tasks.executing <
(this.opts.tasksQueueOptions?.concurrency as number)
} else {
return (
this.workerNodes.findIndex(
- (workerNode) =>
+ workerNode =>
workerNode.info.ready && workerNode.usage.tasks.executing === 0
) === -1
)
workerId: number
): Promise<void> {
await new Promise<void>((resolve, reject) => {
- this.registerWorkerMessageListener(workerNodeKey, (message) => {
+ this.registerWorkerMessageListener(workerNodeKey, message => {
if (message.kill === 'success') {
resolve()
} else if (message.kill === 'failure') {
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
*/
protected createAndSetupDynamicWorkerNode (): number {
const workerNodeKey = this.createAndSetupWorkerNode()
- this.registerWorkerMessageListener(workerNodeKey, (message) => {
+ this.registerWorkerMessageListener(workerNodeKey, message => {
const localWorkerNodeKey = this.getWorkerNodeKeyByWorkerId(
message.workerId
)
workerUsage.tasks.executing === 0 &&
this.tasksQueueSize(localWorkerNodeKey) === 0)))
) {
- this.destroyWorkerNode(localWorkerNodeKey).catch((error) => {
+ this.destroyWorkerNode(localWorkerNodeKey).catch(error => {
this.emitter?.emit(PoolEvents.error, error)
})
}
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
* @returns The listener function to execute when a message is received from a worker.
*/
protected workerListener (): (message: MessageValue<Response>) => void {
- return (message) => {
+ return message => {
this.checkMessageWorkerId(message)
if (message.ready != null && message.taskFunctions != null) {
// Worker ready response received from worker
return (
this.opts.enableTasksQueue === true &&
this.workerNodes.findIndex(
- (workerNode) => !workerNode.hasBackPressure()
+ workerNode => !workerNode.hasBackPressure()
) === -1
)
}
// FIXME: wait for tasks to be finished
const workerNode = this.workerNodes[workerNodeKey]
const worker = workerNode.worker
- const waitWorkerExit = new Promise<void>((resolve) => {
+ const waitWorkerExit = new Promise<void>(resolve => {
worker.on('exit', () => {
resolve()
})
// FIXME: wait for tasks to be finished
const workerNode = this.workerNodes[workerNodeKey]
const worker = workerNode.worker
- const waitWorkerExit = new Promise<void>((resolve) => {
+ const waitWorkerExit = new Promise<void>(resolve => {
worker.on('exit', () => {
resolve()
})
message: MessageValue<Data>,
transferList?: TransferListItem[]
): void {
- ;(
+ (
this.workerNodes[workerNodeKey].messageChannel as MessageChannel
).port1.postMessage(message, transferList)
}
workerNodeKey: number,
listener: (message: MessageValue<Message>) => void
): void {
- ;(
+ (
this.workerNodes[workerNodeKey].messageChannel as MessageChannel
).port1.on('message', listener)
}
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()
* @internal
*/
export const sleep = async (ms: number): Promise<void> => {
- await new Promise((resolve) => {
+ await new Promise(resolve => {
setTimeout(resolve, ms)
})
}
names[names.indexOf(DEFAULT_TASK_NAME)],
defaultTaskFunctionName,
...names.filter(
- (name) => name !== DEFAULT_TASK_NAME && name !== defaultTaskFunctionName
+ name => name !== DEFAULT_TASK_NAME && name !== defaultTaskFunctionName
)
]
}
protected handleKillMessage (message: MessageValue<Data>): void {
this.stopCheckActive()
if (isAsyncFunction(this.opts.killHandler)) {
- ;(this.opts.killHandler?.() as Promise<void>)
+ (this.opts.killHandler?.() as Promise<void>)
.then(() => {
this.sendToMainWorker({ kill: 'success', workerId: this.id })
return null
const { name, taskId, data } = task
let taskPerformance = this.beginTaskPerformance(name)
fn(data)
- .then((res) => {
+ .then(res => {
taskPerformance = this.endTaskPerformance(taskPerformance)
this.sendToMainWorker({
data: res,
})
return null
})
- .catch((e) => {
+ .catch(e => {
const errorMessage = this.handleError(e as Error | string)
this.sendToMainWorker({
taskError: {
numberOfWorkers,
'./tests/worker-files/thread/testWorker.js',
{
- errorHandler: (e) => console.error(e)
+ errorHandler: e => console.error(e)
}
)
).toThrowError(
)
let poolInfo
let poolReady = 0
- pool.emitter.on(PoolEvents.ready, (info) => {
+ pool.emitter.on(PoolEvents.ready, info => {
++poolReady
poolInfo = info
})
const promises = new Set()
let poolBusy = 0
let poolInfo
- pool.emitter.on(PoolEvents.busy, (info) => {
+ pool.emitter.on(PoolEvents.busy, info => {
++poolBusy
poolInfo = info
})
const promises = new Set()
let poolFull = 0
let poolInfo
- pool.emitter.on(PoolEvents.full, (info) => {
+ pool.emitter.on(PoolEvents.full, info => {
++poolFull
poolInfo = info
})
const promises = new Set()
let poolBackPressure = 0
let poolInfo
- pool.emitter.on(PoolEvents.backPressure, (info) => {
+ pool.emitter.on(PoolEvents.backPressure, info => {
++poolBackPressure
poolInfo = info
})
max,
'./tests/worker-files/cluster/testWorker.js',
{
- errorHandler: (e) => console.error(e)
+ errorHandler: e => console.error(e)
}
)
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')
}
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')
}
numberOfWorkers,
'./tests/worker-files/cluster/testWorker.js',
{
- errorHandler: (e) => console.error(e)
+ errorHandler: e => console.error(e)
}
)
const queuePool = new FixedClusterPool(
tasksQueueOptions: {
concurrency: tasksConcurrency
},
- errorHandler: (e) => console.error(e)
+ errorHandler: e => console.error(e)
}
)
const emptyPool = new FixedClusterPool(
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(
numberOfWorkers,
'./tests/worker-files/cluster/testWorker.js',
{
- errorHandler: (e) => console.error(e)
+ errorHandler: e => console.error(e)
}
)
let poolReady = 0
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
})
expect(
errorPool.workerNodes.some(
- (workerNode) => workerNode.usage.tasks.failed === 1
+ workerNode => workerNode.usage.tasks.failed === 1
)
).toBe(true)
})
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
})
expect(
asyncErrorPool.workerNodes.some(
- (workerNode) => workerNode.usage.tasks.failed === 1
+ workerNode => workerNode.usage.tasks.failed === 1
)
).toBe(true)
})
max,
'./tests/worker-files/thread/testWorker.js',
{
- errorHandler: (e) => console.error(e)
+ errorHandler: e => console.error(e)
}
)
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')
}
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')
}
numberOfThreads,
'./tests/worker-files/thread/testWorker.js',
{
- errorHandler: (e) => console.error(e)
+ errorHandler: e => console.error(e)
}
)
const queuePool = new FixedThreadPool(
tasksQueueOptions: {
concurrency: tasksConcurrency
},
- errorHandler: (e) => console.error(e)
+ errorHandler: e => console.error(e)
}
)
const emptyPool = new FixedThreadPool(
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(
numberOfThreads,
'./tests/worker-files/thread/testWorker.js',
{
- errorHandler: (e) => console.error(e)
+ errorHandler: e => console.error(e)
}
)
let poolReady = 0
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
})
expect(
errorPool.workerNodes.some(
- (workerNode) => workerNode.usage.tasks.failed === 1
+ workerNode => workerNode.usage.tasks.failed === 1
)
).toBe(true)
})
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
})
expect(
asyncErrorPool.workerNodes.some(
- (workerNode) => workerNode.usage.tasks.failed === 1
+ workerNode => workerNode.usage.tasks.failed === 1
)
).toBe(true)
})
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)
}
const waitPoolEvents = async (pool, poolEvent, numberOfEventsToWait) => {
- return new Promise((resolve) => {
+ return new Promise(resolve => {
let events = 0
if (numberOfEventsToWait === 0) {
resolve(events)
})
}
-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 (
return Math.floor(Math.random() * (max + 1))
}
-const jsonIntegerSerialization = (n) => {
+const jsonIntegerSerialization = n => {
for (let i = 0; i < n; i++) {
const o = {
a: i
* @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)
}
* @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)
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,
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,
})
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),