module.exports = {
'**/*.{ts,tsx,js,jsx,cjs,mjs}': [
- 'prettier --cache --write',
+ 'rome format --write',
'ts-standard --fix',
'eslint --cache --fix'
],
- '**/*.{json,md,yml,yaml}': ['prettier --cache --write']
+ '**/*.{json,md,yml,yaml}': ['rome format --write']
}
+++ /dev/null
-pnpm-lock.yaml
-.nyc_output/
-coverage/
-reports/
-benchmarks/internal/results/
-docs/**/*.html
-docs/**/*.css
-docs/**/*.js
-outputs/
-lib/
+++ /dev/null
-{
- "$schema": "https://json.schemastore.org/prettierrc",
- "arrowParens": "avoid",
- "semi": false,
- "singleQuote": true,
- "trailingComma": "none"
-}
}
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)
* @param {*} data The worker data.
* @returns {*} The result.
*/
-const functionToBench = data => {
+const functionToBench = (data) => {
const crypto = require('crypto')
const fs = require('fs')
const TaskTypes = {
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', () => {
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) }
})
await FastifyWorker.fastify.register(fastifyPoolifier, workerData)
- FastifyWorker.fastify.all('/api/echo', async request => {
+ FastifyWorker.fastify.all('/api/echo', async (request) => {
return (
await FastifyWorker.fastify.execute({ body: request.body }, 'echo')
).body
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({ body: { 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
}
workerData?.workerFile as string
)
- 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)
"test:debug": "pnpm build && mocha --no-parallel --inspect 'tests/**/*.test.js'",
"coverage": "c8 report --reporter=lcov",
"coverage:html": "c8 report --reporter=html",
- "format": "prettier . --cache --write; ts-standard . --fix",
+ "format": "rome format . --write; ts-standard . --fix",
"lint": "eslint . --cache",
"lint:fix": "eslint . --cache --fix",
"lint:report": "eslint . --cache --format json --output-file reports/eslint.json",
"prepublishOnly": "pnpm build:prod"
},
"ts-standard": {
- "globals": [
- "describe",
- "it",
- "before",
- "after",
- "beforeEach",
- "afterEach"
- ]
+ "globals": ["describe", "it", "before", "after", "beforeEach", "afterEach"]
},
"engines": {
"node": ">=16.14.0",
"url": "https://github.com/poolifier/poolifier/issues"
},
"homepage": "https://github.com/poolifier/poolifier#readme",
- "files": [
- "lib"
- ],
+ "files": ["lib"],
"pnpm": {
"overrides": {
"semver": "^7.5.3"
"microtime": "^3.1.1",
"mocha": "^10.2.0",
"mochawesome": "^7.1.3",
- "prettier": "^3.0.1",
"release-it": "^16.1.5",
"rollup": "^3.28.0",
"rollup-plugin-analyzer": "^4.0.0",
"rollup-plugin-command": "^1.1.3",
"rollup-plugin-delete": "^2.0.0",
+ "rome": "^12.1.3",
"sinon": "^15.2.0",
"source-map-support": "^0.5.21",
"ts-standard": "^12.0.2",
mochawesome:
specifier: ^7.1.3
version: 7.1.3(mocha@10.2.0)
- prettier:
- specifier: ^3.0.1
- version: 3.0.1
release-it:
specifier: ^16.1.5
version: 16.1.5
rollup-plugin-delete:
specifier: ^2.0.0
version: 2.0.0
+ rome:
+ specifier: ^12.1.3
+ version: 12.1.3
sinon:
specifier: ^15.2.0
version: 15.2.0
rollup: 3.28.0
dev: true
+ /@rometools/cli-darwin-arm64@12.1.3:
+ resolution: {integrity: sha512-AmFTUDYjBuEGQp/Wwps+2cqUr+qhR7gyXAUnkL5psCuNCz3807TrUq/ecOoct5MIavGJTH6R4aaSL6+f+VlBEg==}
+ cpu: [arm64]
+ os: [darwin]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@rometools/cli-darwin-x64@12.1.3:
+ resolution: {integrity: sha512-k8MbWna8q4LRlb005N2X+JS1UQ+s3ZLBBvwk4fP8TBxlAJXUz17jLLu/Fi+7DTTEmMhM84TWj4FDKW+rNar28g==}
+ cpu: [x64]
+ os: [darwin]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@rometools/cli-linux-arm64@12.1.3:
+ resolution: {integrity: sha512-X/uLhJ2/FNA3nu5TiyeNPqiD3OZoFfNfRvw6a3ut0jEREPvEn72NI7WPijH/gxSz55znfQ7UQ6iM4DZumUknJg==}
+ cpu: [arm64]
+ os: [linux]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@rometools/cli-linux-x64@12.1.3:
+ resolution: {integrity: sha512-csP17q1eWiUXx9z6Jr/JJPibkplyKIwiWPYNzvPCGE8pHlKhwZj3YHRuu7Dm/4EOqx0XFIuqqWZUYm9bkIC8xg==}
+ cpu: [x64]
+ os: [linux]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@rometools/cli-win32-arm64@12.1.3:
+ resolution: {integrity: sha512-RymHWeod57EBOJY4P636CgUwYA6BQdkQjh56XKk4pLEHO6X1bFyMet2XL7KlHw5qOTalzuzf5jJqUs+vf3jdXQ==}
+ cpu: [arm64]
+ os: [win32]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ /@rometools/cli-win32-x64@12.1.3:
+ resolution: {integrity: sha512-yHSKYidqJMV9nADqg78GYA+cZ0hS1twANAjiFibQdXj9aGzD+s/IzIFEIi/U/OBLvWYg/SCw0QVozi2vTlKFDQ==}
+ cpu: [x64]
+ os: [win32]
+ requiresBuild: true
+ dev: true
+ optional: true
+
/@sinclair/typebox@0.27.8:
resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==}
dev: true
engines: {node: '>= 0.8.0'}
dev: true
- /prettier@3.0.1:
- resolution: {integrity: sha512-fcOWSnnpCrovBsmFZIGIy9UqK2FaI7Hqax+DIO0A9UxeVoY4iweyaFjS5TavZN97Hfehph0nhsZnjlVKzEQSrQ==}
- engines: {node: '>=14'}
- hasBin: true
- dev: true
-
/pretty-format@29.6.2:
resolution: {integrity: sha512-1q0oC8eRveTg5nnBEWMXAU2qpv65Gnuf2eCQzSjxpWFkPaPARwqZZDGuNE0zPAZfTCHzIk3A8dIjwlQKKLphyg==}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
fsevents: 2.3.2
dev: true
+ /rome@12.1.3:
+ resolution: {integrity: sha512-e+ff72hxDpe/t5/Us7YRBVw3PBET7SeczTQNn6tvrWdrCaAw3qOukQQ+tDCkyFtS4yGsnhjrJbm43ctNbz27Yg==}
+ engines: {node: '>=14.*'}
+ hasBin: true
+ requiresBuild: true
+ optionalDependencies:
+ '@rometools/cli-darwin-arm64': 12.1.3
+ '@rometools/cli-darwin-x64': 12.1.3
+ '@rometools/cli-linux-arm64': 12.1.3
+ '@rometools/cli-linux-x64': 12.1.3
+ '@rometools/cli-win32-arm64': 12.1.3
+ '@rometools/cli-win32-x64': 12.1.3
+ dev: true
+
/run-applescript@5.0.0:
resolution: {integrity: sha512-XcT5rBksx1QdIhlFOCtgZkB99ZEouFZ1E2Kc2LHqNW13U3/74YGdkQRmThTwxy4QIyookibDKYZOPqX//6BlAg==}
engines: {node: '>=12'}
--- /dev/null
+{
+ "$schema": "https://docs.rome.tools/schemas/12.1.3/schema.json",
+ "organizeImports": {
+ "enabled": false
+ },
+ "linter": {
+ "enabled": true,
+ "rules": {
+ "recommended": true
+ }
+ },
+ "formatter": {
+ "enabled": true,
+ "indentStyle": "space",
+ "indentSize": 2
+ },
+ "javascript": {
+ "formatter": {
+ "quoteStyle": "single",
+ "trailingComma": "none",
+ "semicolons": "asNeeded"
+ }
+ },
+ "files": {
+ "ignore": [
+ ".vscode/",
+ ".nyc_output/",
+ "benchmarks/internal/results/",
+ "coverage/",
+ "docs/**/*.css",
+ "docs/**/*.html",
+ "docs/**/*.js",
+ "lib/",
+ "outputs/",
+ "pnpm-lock.yaml",
+ "reports/"
+ ]
+ }
+}
minimum: round(
Math.min(
...this.workerNodes.map(
- workerNode => workerNode.usage.runTime?.minimum ?? Infinity
+ (workerNode) => workerNode.usage.runTime?.minimum ?? Infinity
)
)
),
maximum: round(
Math.max(
...this.workerNodes.map(
- workerNode => workerNode.usage.runTime?.maximum ?? -Infinity
+ (workerNode) => workerNode.usage.runTime?.maximum ?? -Infinity
)
)
),
median: round(
median(
this.workerNodes.map(
- workerNode => workerNode.usage.runTime?.median ?? 0
+ (workerNode) => workerNode.usage.runTime?.median ?? 0
)
)
)
minimum: round(
Math.min(
...this.workerNodes.map(
- workerNode => workerNode.usage.waitTime?.minimum ?? Infinity
+ (workerNode) => workerNode.usage.waitTime?.minimum ?? Infinity
)
)
),
maximum: round(
Math.max(
...this.workerNodes.map(
- workerNode => workerNode.usage.waitTime?.maximum ?? -Infinity
+ (workerNode) => workerNode.usage.waitTime?.maximum ?? -Infinity
)
)
),
median: round(
median(
this.workerNodes.map(
- workerNode => workerNode.usage.waitTime?.median ?? 0
+ (workerNode) => workerNode.usage.waitTime?.median ?? 0
)
)
)
*/
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
)
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
)
* @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) {
// Worker ready response received from worker
this.flushTasksQueue(workerNodeKey)
// FIXME: wait for tasks to be finished
const worker = this.workerNodes[workerNodeKey].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()
})
this.taskFunctions.set(DEFAULT_TASK_NAME, boundFn)
this.taskFunctions.set(
typeof taskFunctions.name === 'string' &&
- taskFunctions.name.trim().length > 0
+ taskFunctions.name.trim().length > 0
? taskFunctions.name
: 'fn1',
boundFn
): void {
let taskPerformance = this.beginTaskPerformance(task.name)
fn(task.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('Cannot start a pool from a worker!')
const promises = new Set()
let poolFull = 0
let poolInfo
- pool.emitter.on(PoolEvents.full, info => {
+ pool.emitter.on(PoolEvents.full, (info) => {
++poolFull
poolInfo = info
})
)
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
})
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)
},
{
maxInactiveTime: 500,
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)
},
{
maxInactiveTime: 500,
})
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),