ecmaVersion: 2020,
sourceType: 'module'
},
- plugins: ['@typescript-eslint', 'promise', 'prettierx', 'jsdoc'],
+ plugins: [
+ '@typescript-eslint',
+ 'promise',
+ 'prettierx',
+ 'jsdoc',
+ 'spellcheck'
+ ],
extends: [
'standard',
'eslint:recommended',
ignoreMemberSort: true,
ignoreDeclarationSort: true
}
+ ],
+
+ 'spellcheck/spell-checker': [
+ 'warn',
+ {
+ skipWords: [
+ 'poolifier',
+ 'pioardi',
+ 'christopher',
+ 'ecma',
+ 'jsdoc',
+ 'readonly',
+ 'serializable',
+ 'unregister',
+ 'workerpool'
+ ],
+ skipIfMatch: ['^@.*', '^plugin:.*']
+ }
]
},
overrides: [
.vscode/*
!.vscode/extensions.json
!.vscode/launch.json
+!.vscode/settings.json
!.vscode/tasks.json
# Mac
--- /dev/null
+{
+ "cSpell.words": [
+ "Alessandro",
+ "Ardizio",
+ "Benoit",
+ "Dependabot",
+ "Gitter",
+ "Shinigami",
+ "lcov",
+ "loglevel",
+ "markdownlint",
+ "piment",
+ "pioardi",
+ "poolifier",
+ "prettierx",
+ "serializable",
+ "standardx",
+ "workerpool"
+ ]
+}
For cluster and thread pools, you can now only send and receive serializable `JSON` data.
_This is not a limitation by poolifier but NodeJS._
+#### Public properties renaming
+
+- Thread Pool's `numWorkers` is now `numberOfWorkers`
+
#### Internal (protected) methods renaming
Those methods are not intended to be used from final users
const { FixedThreadPool } = require('poolifier')
-const pool = new FixedThreadPool(15, './multifunctionWorker.js', {
+const pool = new FixedThreadPool(15, './multiFunctionWorker.js', {
errorHandler: e => console.error(e),
onlineHandler: () => console.log('worker is online')
})
pool
- .execute({ fname: 'fn0', input: 'hello' })
+ .execute({ functionName: 'fn0', input: 'hello' })
.then(res => console.log(res))
.catch(err => console.error(err))
pool
- .execute({ fname: 'fn1', input: 'multifunction' })
+ .execute({ functionName: 'fn1', input: 'multiple functions' })
.then(res => console.log(res))
.catch(err => console.error(err))
const { ThreadWorker } = require('poolifier')
function yourFunction (data) {
- if (data.fname === 'fn0') {
+ if (data.functionName === 'fn0') {
console.log('Executing function 0')
return { data: '0 your input was' + data.input }
- } else if (data.fname === 'fn1') {
+ } else if (data.functionName === 'fn1') {
console.log('Executing function 1')
return { data: '1 your input was' + data.input }
}
}
},
"@istanbuljs/schema": {
- "version": "0.1.2",
- "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.2.tgz",
- "integrity": "sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw==",
+ "version": "0.1.3",
+ "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz",
+ "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==",
"dev": true
},
"@jest/types": {
"integrity": "sha512-bY2sGqyptzFBDLh/GMbAxfdJC+b0f23ME63FOE4+Jao0oZ3E1LEwFtWJX/1pGMJLiTtrSSern2CRM/g+dfc0eQ==",
"dev": true
},
+ "eslint-plugin-spellcheck": {
+ "version": "0.0.17",
+ "resolved": "https://registry.npmjs.org/eslint-plugin-spellcheck/-/eslint-plugin-spellcheck-0.0.17.tgz",
+ "integrity": "sha512-SjEPsqHgAODWgCusCXxzYqTkJHe8krun7UjekzhWkFlGM3ZTPto66ED+kQHBrOB3Mrqkx3oD0qf0sDmxyeCRCA==",
+ "dev": true,
+ "requires": {
+ "globals": "^13.0.0",
+ "hunspell-spellchecker": "^1.0.2",
+ "lodash": "^4.17.15"
+ },
+ "dependencies": {
+ "globals": {
+ "version": "13.5.0",
+ "resolved": "https://registry.npmjs.org/globals/-/globals-13.5.0.tgz",
+ "integrity": "sha512-TMJe2Iu/qCIEFnG7IQ62C9N/iKdgX5wSvmGOVuk75+UAGDW+Yv/hH5+Ky6d/8UMqo4WCzhFCy+pHsvv09zhBoQ==",
+ "dev": true,
+ "requires": {
+ "type-fest": "^0.20.2"
+ }
+ },
+ "type-fest": {
+ "version": "0.20.2",
+ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz",
+ "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==",
+ "dev": true
+ }
+ }
+ },
"eslint-scope": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
"integrity": "sha512-uE/TxKuyNIcx44cIWnjr/rfIATDH7ZaOMmstu0CwhFG1Dunhlp4OC6/NMbhiwoq5BpW0ubi303qnEk/PZj614w==",
"dev": true
},
+ "hunspell-spellchecker": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/hunspell-spellchecker/-/hunspell-spellchecker-1.0.2.tgz",
+ "integrity": "sha1-oQsL0voAplq2Kkxrc0zkltMYkQ4=",
+ "dev": true
+ },
"ignore": {
"version": "5.1.8",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettierx": "^0.17.1",
"eslint-plugin-promise": "^4.3.1",
+ "eslint-plugin-spellcheck": "0.0.17",
"expect": "^26.6.2",
"mocha": "^8.3.0",
"mocha-lcov-reporter": "^1.3.0",
/**
* Constructs a new poolifier pool.
*
- * @param numWorkers Number of workers that this pool should manage.
+ * @param numberOfWorkers Number of workers that this pool should manage.
* @param filePath Path to the worker-file.
* @param opts Options for the pool. Default: `{ maxTasks: 1000 }`
*/
public constructor (
- public readonly numWorkers: number,
+ public readonly numberOfWorkers: number,
public readonly filePath: string,
public readonly opts: PoolOptions<Worker> = { maxTasks: 1000 }
) {
this.setupHook()
- for (let i = 1; i <= this.numWorkers; i++) {
+ for (let i = 1; i <= this.numberOfWorkers; i++) {
this.internalNewWorker()
}
}
/**
- * Setup hook that can be overridden by a Poolifer pool implementation
+ * Number of workers that this pool should manage.
+ *
+ * @returns Number of workers that this pool manages.
+ * @deprecated Only here for backward compatibility.
+ */
+ // eslint-disable-next-line spellcheck/spell-checker
+ public get numWorkers (): number {
+ return this.numberOfWorkers
+ }
+
+ /**
+ * Setup hook that can be overridden by a Poolifier pool implementation
* to run code before workers are created in the abstract constructor.
*/
protected setupHook (): void {
/**
* Constructs a new poolifier fixed cluster pool.
*
- * @param numWorkers Number of workers for this pool.
+ * @param numberOfWorkers Number of workers for this pool.
* @param filePath Path to an implementation of a `ClusterWorker` file, which can be relative or absolute.
* @param opts Options for this fixed cluster pool. Default: `{ maxTasks: 1000 }`
*/
public constructor (
- numWorkers: number,
+ numberOfWorkers: number,
filePath: string,
public readonly opts: ClusterPoolOptions = { maxTasks: 1000 }
) {
- super(numWorkers, filePath, opts)
+ super(numberOfWorkers, filePath, opts)
}
protected setupHook (): void {
/**
* Constructs a new poolifier fixed thread pool.
*
- * @param numThreads Number of threads for this pool.
+ * @param numberOfThreads Number of threads for this pool.
* @param filePath Path to an implementation of a `ThreadWorker` file, which can be relative or absolute.
* @param opts Options for this fixed thread pool. Default: `{ maxTasks: 1000 }`
*/
public constructor (
- numThreads: number,
+ numberOfThreads: number,
filePath: string,
opts: PoolOptions<ThreadWorkerWithMessageChannel> = { maxTasks: 1000 }
) {
- super(numThreads, filePath, opts)
+ super(numberOfThreads, filePath, opts)
}
protected isMain (): boolean {
const expect = require('expect')
const { FixedClusterPool } = require('../../../lib/index')
-const numWorkers = 10
+const numberOfWorkers = 10
const maxTasks = 500
const pool = new FixedClusterPool(
- numWorkers,
+ numberOfWorkers,
'./tests/worker/cluster/testWorker.js',
{
errorHandler: e => console.error(e),
describe('Fixed cluster pool test suite ', () => {
it('Choose worker round robin test', async () => {
const results = new Set()
- for (let i = 0; i < numWorkers; i++) {
+ for (let i = 0; i < numberOfWorkers; i++) {
results.add(pool.chooseWorker().id)
}
- expect(results.size).toBe(numWorkers)
+ expect(results.size).toBe(numberOfWorkers)
})
it('Verify that the function is executed in a worker cluster', async () => {
})
pool.destroy()
await new Promise(resolve => setTimeout(resolve, 200))
- expect(closedWorkers).toBe(numWorkers)
+ expect(closedWorkers).toBe(numberOfWorkers)
})
it('Validations test', () => {
const expect = require('expect')
const { FixedThreadPool } = require('../../../lib/index')
-const numThreads = 10
+const numberOfThreads = 10
const maxTasks = 400
const pool = new FixedThreadPool(
- numThreads,
+ numberOfThreads,
'./tests/worker/thread/testWorker.js',
{
errorHandler: e => console.error(e),
describe('Fixed thread pool test suite ', () => {
it('Choose worker round robin test', async () => {
const results = new Set()
- for (let i = 0; i < numThreads; i++) {
+ for (let i = 0; i < numberOfThreads; i++) {
results.add(pool.chooseWorker().threadId)
}
- expect(results.size).toBe(numThreads)
+ expect(results.size).toBe(numberOfThreads)
})
it('Verify that the function is executed in a worker thread', async () => {
})
})
await pool.destroy()
- expect(closedThreads).toBe(numThreads)
+ expect(closedThreads).toBe(numberOfThreads)
})
it('Validations test', () => {