Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
17 files changed:
+### Added
+
+- Add `PoolEvents` enumeration and `PoolEvent` type.
+
-- fix: destroy worker only on check alive.
+- fix: destroy worker only on alive check.
-const { FixedThreadPool, DynamicThreadPool } = require('poolifier')
+const { DynamicThreadPool, FixedThreadPool, PoolEvents } = require('poolifier')
// a fixed worker-threads pool
const pool = new FixedThreadPool(15,
'./yourWorker.js',
{ errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') })
// a fixed worker-threads pool
const pool = new FixedThreadPool(15,
'./yourWorker.js',
{ errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') })
-pool.emitter.on('busy', () => console.log('Pool is busy'))
+pool.emitter.on(PoolEvents.busy, () => console.log('Pool is busy'))
// or a dynamic worker-threads pool
const pool = new DynamicThreadPool(10, 100,
'./yourWorker.js',
{ errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') })
// or a dynamic worker-threads pool
const pool = new DynamicThreadPool(10, 100,
'./yourWorker.js',
{ errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') })
-pool.emitter.on('full', () => console.log('Pool is full'))
-pool.emitter.on('busy', () => console.log('Pool is busy'))
+pool.emitter.on(PoolEvents.full, () => console.log('Pool is full'))
+pool.emitter.on(PoolEvents.busy, () => console.log('Pool is busy'))
// the execute method signature is the same for both implementations,
// so you can easy switch from one to another
// the execute method signature is the same for both implementations,
// so you can easy switch from one to another
-const { DynamicThreadPool } = require('poolifier')
+const { DynamicThreadPool, PoolEvents } = require('poolifier')
let resolved = 0
let poolFull = 0
let poolBusy = 0
let resolved = 0
let poolFull = 0
let poolBusy = 0
errorHandler: e => console.error(e),
onlineHandler: () => console.log('worker is online')
})
errorHandler: e => console.error(e),
onlineHandler: () => console.log('worker is online')
})
-pool.emitter.on('full', () => poolFull++)
-pool.emitter.on('busy', () => poolBusy++)
+pool.emitter.on(PoolEvents.full, () => poolFull++)
+pool.emitter.on(PoolEvents.busy, () => poolBusy++)
const start = Date.now()
const iterations = 1000
const start = Date.now()
const iterations = 1000
-const { FixedThreadPool } = require('poolifier')
+const { FixedThreadPool, PoolEvents } = require('poolifier')
let resolved = 0
let poolBusy = 0
const pool = new FixedThreadPool(15, './yourWorker.js', {
errorHandler: e => console.error(e),
onlineHandler: () => console.log('worker is online')
})
let resolved = 0
let poolBusy = 0
const pool = new FixedThreadPool(15, './yourWorker.js', {
errorHandler: e => console.error(e),
onlineHandler: () => console.log('worker is online')
})
-pool.emitter.on('busy', () => poolBusy++)
+pool.emitter.on(PoolEvents.busy, () => poolBusy++)
const start = Date.now()
const iterations = 1000
const start = Date.now()
const iterations = 1000
"source-map-support": "^0.5.21",
"ts-standard": "^12.0.2",
"typedoc": "^0.23.28",
"source-map-support": "^0.5.21",
"ts-standard": "^12.0.2",
"typedoc": "^0.23.28",
version: 0.4.0(rollup@3.20.2)
'@rollup/plugin-typescript':
specifier: ^11.1.0
version: 0.4.0(rollup@3.20.2)
'@rollup/plugin-typescript':
specifier: ^11.1.0
- version: 11.1.0(rollup@3.20.2)(typescript@5.0.3)
+ version: 11.1.0(rollup@3.20.2)(typescript@5.0.4)
'@types/node':
specifier: ^18.15.11
version: 18.15.11
'@typescript-eslint/eslint-plugin':
specifier: ^5.57.1
'@types/node':
specifier: ^18.15.11
version: 18.15.11
'@typescript-eslint/eslint-plugin':
specifier: ^5.57.1
- version: 5.57.1(@typescript-eslint/parser@5.57.1)(eslint@8.37.0)(typescript@5.0.3)
+ version: 5.57.1(@typescript-eslint/parser@5.57.1)(eslint@8.37.0)(typescript@5.0.4)
'@typescript-eslint/parser':
specifier: ^5.57.1
'@typescript-eslint/parser':
specifier: ^5.57.1
- version: 5.57.1(eslint@8.37.0)(typescript@5.0.3)
+ version: 5.57.1(eslint@8.37.0)(typescript@5.0.4)
benny:
specifier: ^3.7.1
version: 3.7.1
benny:
specifier: ^3.7.1
version: 3.7.1
version: 17.0.0(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)
eslint-config-standard-with-typescript:
specifier: ^34.0.1
version: 17.0.0(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)
eslint-config-standard-with-typescript:
specifier: ^34.0.1
- version: 34.0.1(@typescript-eslint/eslint-plugin@5.57.1)(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)(typescript@5.0.3)
+ version: 34.0.1(@typescript-eslint/eslint-plugin@5.57.1)(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)(typescript@5.0.4)
eslint-define-config:
specifier: ^1.17.0
version: 1.17.0
eslint-define-config:
specifier: ^1.17.0
version: 1.17.0
version: 2.8.7
prettier-plugin-organize-imports:
specifier: ^3.2.2
version: 2.8.7
prettier-plugin-organize-imports:
specifier: ^3.2.2
- version: 3.2.2(prettier@2.8.7)(typescript@5.0.3)
+ version: 3.2.2(prettier@2.8.7)(typescript@5.0.4)
release-it:
specifier: ^15.10.1
version: 15.10.1
release-it:
specifier: ^15.10.1
version: 15.10.1
version: 0.5.21
ts-standard:
specifier: ^12.0.2
version: 0.5.21
ts-standard:
specifier: ^12.0.2
- version: 12.0.2(eslint-import-resolver-typescript@3.5.5)(typescript@5.0.3)
+ version: 12.0.2(eslint-import-resolver-typescript@3.5.5)(typescript@5.0.4)
typedoc:
specifier: ^0.23.28
typedoc:
specifier: ^0.23.28
- version: 0.23.28(typescript@5.0.3)
+ version: 0.23.28(typescript@5.0.4)
- specifier: ^5.0.3
- version: 5.0.3
+ specifier: ^5.0.4
+ version: 5.0.4
'@types/node': 18.15.11
chalk: 4.1.2
cosmiconfig: 8.1.3
'@types/node': 18.15.11
chalk: 4.1.2
cosmiconfig: 8.1.3
- cosmiconfig-typescript-loader: 4.3.0(@types/node@18.15.11)(cosmiconfig@8.1.3)(ts-node@10.9.1)(typescript@5.0.3)
+ cosmiconfig-typescript-loader: 4.3.0(@types/node@18.15.11)(cosmiconfig@8.1.3)(ts-node@10.9.1)(typescript@5.0.4)
lodash.isplainobject: 4.0.6
lodash.merge: 4.6.2
lodash.uniq: 4.5.0
resolve-from: 5.0.0
lodash.isplainobject: 4.0.6
lodash.merge: 4.6.2
lodash.uniq: 4.5.0
resolve-from: 5.0.0
- ts-node: 10.9.1(@types/node@18.15.11)(typescript@5.0.3)
- typescript: 5.0.3
+ ts-node: 10.9.1(@types/node@18.15.11)(typescript@5.0.4)
+ typescript: 5.0.4
transitivePeerDependencies:
- '@swc/core'
- '@swc/wasm'
transitivePeerDependencies:
- '@swc/core'
- '@swc/wasm'
- /@rollup/plugin-typescript@11.1.0(rollup@3.20.2)(typescript@5.0.3):
+ /@rollup/plugin-typescript@11.1.0(rollup@3.20.2)(typescript@5.0.4):
resolution: {integrity: sha512-86flrfE+bSHB69znnTV6kVjkncs2LBMhcTCyxWgRxLyfXfQrxg4UwlAqENnjrrxnSNS/XKCDJCl8EkdFJVHOxw==}
engines: {node: '>=14.0.0'}
peerDependencies:
resolution: {integrity: sha512-86flrfE+bSHB69znnTV6kVjkncs2LBMhcTCyxWgRxLyfXfQrxg4UwlAqENnjrrxnSNS/XKCDJCl8EkdFJVHOxw==}
engines: {node: '>=14.0.0'}
peerDependencies:
'@rollup/pluginutils': 5.0.2(rollup@3.20.2)
resolve: 1.22.2
rollup: 3.20.2
'@rollup/pluginutils': 5.0.2(rollup@3.20.2)
resolve: 1.22.2
rollup: 3.20.2
dev: true
/@rollup/pluginutils@5.0.2(rollup@3.20.2):
dev: true
/@rollup/pluginutils@5.0.2(rollup@3.20.2):
'@types/yargs-parser': 21.0.0
dev: true
'@types/yargs-parser': 21.0.0
dev: true
- /@typescript-eslint/eslint-plugin@5.57.1(@typescript-eslint/parser@5.57.1)(eslint@8.37.0)(typescript@5.0.3):
+ /@typescript-eslint/eslint-plugin@5.57.1(@typescript-eslint/parser@5.57.1)(eslint@8.37.0)(typescript@5.0.4):
resolution: {integrity: sha512-1MeobQkQ9tztuleT3v72XmY0XuKXVXusAhryoLuU5YZ+mXoYKZP9SQ7Flulh1NX4DTjpGTc2b/eMu4u7M7dhnQ==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
resolution: {integrity: sha512-1MeobQkQ9tztuleT3v72XmY0XuKXVXusAhryoLuU5YZ+mXoYKZP9SQ7Flulh1NX4DTjpGTc2b/eMu4u7M7dhnQ==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
optional: true
dependencies:
'@eslint-community/regexpp': 4.5.0
optional: true
dependencies:
'@eslint-community/regexpp': 4.5.0
- '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.3)
+ '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.4)
'@typescript-eslint/scope-manager': 5.57.1
'@typescript-eslint/scope-manager': 5.57.1
- '@typescript-eslint/type-utils': 5.57.1(eslint@8.37.0)(typescript@5.0.3)
- '@typescript-eslint/utils': 5.57.1(eslint@8.37.0)(typescript@5.0.3)
+ '@typescript-eslint/type-utils': 5.57.1(eslint@8.37.0)(typescript@5.0.4)
+ '@typescript-eslint/utils': 5.57.1(eslint@8.37.0)(typescript@5.0.4)
debug: 4.3.4(supports-color@8.1.1)
eslint: 8.37.0
grapheme-splitter: 1.0.4
ignore: 5.2.4
natural-compare-lite: 1.4.0
semver: 7.3.8
debug: 4.3.4(supports-color@8.1.1)
eslint: 8.37.0
grapheme-splitter: 1.0.4
ignore: 5.2.4
natural-compare-lite: 1.4.0
semver: 7.3.8
- tsutils: 3.21.0(typescript@5.0.3)
- typescript: 5.0.3
+ tsutils: 3.21.0(typescript@5.0.4)
+ typescript: 5.0.4
transitivePeerDependencies:
- supports-color
dev: true
transitivePeerDependencies:
- supports-color
dev: true
- /@typescript-eslint/parser@5.57.1(eslint@8.37.0)(typescript@5.0.3):
+ /@typescript-eslint/parser@5.57.1(eslint@8.37.0)(typescript@5.0.4):
resolution: {integrity: sha512-hlA0BLeVSA/wBPKdPGxoVr9Pp6GutGoY380FEhbVi0Ph4WNe8kLvqIRx76RSQt1lynZKfrXKs0/XeEk4zZycuA==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
resolution: {integrity: sha512-hlA0BLeVSA/wBPKdPGxoVr9Pp6GutGoY380FEhbVi0Ph4WNe8kLvqIRx76RSQt1lynZKfrXKs0/XeEk4zZycuA==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
dependencies:
'@typescript-eslint/scope-manager': 5.57.1
'@typescript-eslint/types': 5.57.1
dependencies:
'@typescript-eslint/scope-manager': 5.57.1
'@typescript-eslint/types': 5.57.1
- '@typescript-eslint/typescript-estree': 5.57.1(typescript@5.0.3)
+ '@typescript-eslint/typescript-estree': 5.57.1(typescript@5.0.4)
debug: 4.3.4(supports-color@8.1.1)
eslint: 8.37.0
debug: 4.3.4(supports-color@8.1.1)
eslint: 8.37.0
transitivePeerDependencies:
- supports-color
dev: true
transitivePeerDependencies:
- supports-color
dev: true
'@typescript-eslint/visitor-keys': 5.57.1
dev: true
'@typescript-eslint/visitor-keys': 5.57.1
dev: true
- /@typescript-eslint/type-utils@5.57.1(eslint@8.37.0)(typescript@5.0.3):
+ /@typescript-eslint/type-utils@5.57.1(eslint@8.37.0)(typescript@5.0.4):
resolution: {integrity: sha512-/RIPQyx60Pt6ga86hKXesXkJ2WOS4UemFrmmq/7eOyiYjYv/MUSHPlkhU6k9T9W1ytnTJueqASW+wOmW4KrViw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
resolution: {integrity: sha512-/RIPQyx60Pt6ga86hKXesXkJ2WOS4UemFrmmq/7eOyiYjYv/MUSHPlkhU6k9T9W1ytnTJueqASW+wOmW4KrViw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
typescript:
optional: true
dependencies:
typescript:
optional: true
dependencies:
- '@typescript-eslint/typescript-estree': 5.57.1(typescript@5.0.3)
- '@typescript-eslint/utils': 5.57.1(eslint@8.37.0)(typescript@5.0.3)
+ '@typescript-eslint/typescript-estree': 5.57.1(typescript@5.0.4)
+ '@typescript-eslint/utils': 5.57.1(eslint@8.37.0)(typescript@5.0.4)
debug: 4.3.4(supports-color@8.1.1)
eslint: 8.37.0
debug: 4.3.4(supports-color@8.1.1)
eslint: 8.37.0
- tsutils: 3.21.0(typescript@5.0.3)
- typescript: 5.0.3
+ tsutils: 3.21.0(typescript@5.0.4)
+ typescript: 5.0.4
transitivePeerDependencies:
- supports-color
dev: true
transitivePeerDependencies:
- supports-color
dev: true
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dev: true
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dev: true
- /@typescript-eslint/typescript-estree@5.57.1(typescript@5.0.3):
+ /@typescript-eslint/typescript-estree@5.57.1(typescript@5.0.4):
resolution: {integrity: sha512-A2MZqD8gNT0qHKbk2wRspg7cHbCDCk2tcqt6ScCFLr5Ru8cn+TCfM786DjPhqwseiS+PrYwcXht5ztpEQ6TFTw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
resolution: {integrity: sha512-A2MZqD8gNT0qHKbk2wRspg7cHbCDCk2tcqt6ScCFLr5Ru8cn+TCfM786DjPhqwseiS+PrYwcXht5ztpEQ6TFTw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
globby: 11.1.0
is-glob: 4.0.3
semver: 7.3.8
globby: 11.1.0
is-glob: 4.0.3
semver: 7.3.8
- tsutils: 3.21.0(typescript@5.0.3)
- typescript: 5.0.3
+ tsutils: 3.21.0(typescript@5.0.4)
+ typescript: 5.0.4
transitivePeerDependencies:
- supports-color
dev: true
transitivePeerDependencies:
- supports-color
dev: true
- /@typescript-eslint/utils@5.57.1(eslint@8.37.0)(typescript@5.0.3):
+ /@typescript-eslint/utils@5.57.1(eslint@8.37.0)(typescript@5.0.4):
resolution: {integrity: sha512-kN6vzzf9NkEtawECqze6v99LtmDiUJCVpvieTFA1uL7/jDghiJGubGZ5csicYHU1Xoqb3oH/R5cN5df6W41Nfg==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
resolution: {integrity: sha512-kN6vzzf9NkEtawECqze6v99LtmDiUJCVpvieTFA1uL7/jDghiJGubGZ5csicYHU1Xoqb3oH/R5cN5df6W41Nfg==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
'@types/semver': 7.3.13
'@typescript-eslint/scope-manager': 5.57.1
'@typescript-eslint/types': 5.57.1
'@types/semver': 7.3.13
'@typescript-eslint/scope-manager': 5.57.1
'@typescript-eslint/types': 5.57.1
- '@typescript-eslint/typescript-estree': 5.57.1(typescript@5.0.3)
+ '@typescript-eslint/typescript-estree': 5.57.1(typescript@5.0.4)
eslint: 8.37.0
eslint-scope: 5.1.1
semver: 7.3.8
eslint: 8.37.0
eslint-scope: 5.1.1
semver: 7.3.8
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
dev: true
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
dev: true
- /cosmiconfig-typescript-loader@4.3.0(@types/node@18.15.11)(cosmiconfig@8.1.3)(ts-node@10.9.1)(typescript@5.0.3):
+ /cosmiconfig-typescript-loader@4.3.0(@types/node@18.15.11)(cosmiconfig@8.1.3)(ts-node@10.9.1)(typescript@5.0.4):
resolution: {integrity: sha512-NTxV1MFfZDLPiBMjxbHRwSh5LaLcPMwNdCutmnHJCKoVnlvldPWlllonKwrsRJ5pYZBIBGRWWU2tfvzxgeSW5Q==}
engines: {node: '>=12', npm: '>=6'}
peerDependencies:
resolution: {integrity: sha512-NTxV1MFfZDLPiBMjxbHRwSh5LaLcPMwNdCutmnHJCKoVnlvldPWlllonKwrsRJ5pYZBIBGRWWU2tfvzxgeSW5Q==}
engines: {node: '>=12', npm: '>=6'}
peerDependencies:
dependencies:
'@types/node': 18.15.11
cosmiconfig: 8.1.3
dependencies:
'@types/node': 18.15.11
cosmiconfig: 8.1.3
- ts-node: 10.9.1(@types/node@18.15.11)(typescript@5.0.3)
- typescript: 5.0.3
+ ts-node: 10.9.1(@types/node@18.15.11)(typescript@5.0.4)
+ typescript: 5.0.4
dev: true
/cosmiconfig@8.1.3:
dev: true
/cosmiconfig@8.1.3:
eslint-plugin-react: 7.32.2(eslint@8.37.0)
dev: true
eslint-plugin-react: 7.32.2(eslint@8.37.0)
dev: true
- /eslint-config-standard-with-typescript@23.0.0(@typescript-eslint/eslint-plugin@5.57.1)(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)(typescript@5.0.3):
+ /eslint-config-standard-with-typescript@23.0.0(@typescript-eslint/eslint-plugin@5.57.1)(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)(typescript@5.0.4):
resolution: {integrity: sha512-iaaWifImn37Z1OXbNW1es7KI+S7D408F9ys0bpaQf2temeBWlvb0Nc5qHkOgYaRb5QxTZT32GGeN1gtswASOXA==}
peerDependencies:
'@typescript-eslint/eslint-plugin': ^5.0.0
resolution: {integrity: sha512-iaaWifImn37Z1OXbNW1es7KI+S7D408F9ys0bpaQf2temeBWlvb0Nc5qHkOgYaRb5QxTZT32GGeN1gtswASOXA==}
peerDependencies:
'@typescript-eslint/eslint-plugin': ^5.0.0
eslint-plugin-promise: ^6.0.0
typescript: '*'
dependencies:
eslint-plugin-promise: ^6.0.0
typescript: '*'
dependencies:
- '@typescript-eslint/eslint-plugin': 5.57.1(@typescript-eslint/parser@5.57.1)(eslint@8.37.0)(typescript@5.0.3)
- '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.3)
+ '@typescript-eslint/eslint-plugin': 5.57.1(@typescript-eslint/parser@5.57.1)(eslint@8.37.0)(typescript@5.0.4)
+ '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.4)
eslint: 8.37.0
eslint-config-standard: 17.0.0(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)
eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.57.1)(eslint-import-resolver-typescript@3.5.5)(eslint@8.37.0)
eslint-plugin-n: 15.7.0(eslint@8.37.0)
eslint-plugin-promise: 6.1.1(eslint@8.37.0)
eslint: 8.37.0
eslint-config-standard: 17.0.0(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)
eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.57.1)(eslint-import-resolver-typescript@3.5.5)(eslint@8.37.0)
eslint-plugin-n: 15.7.0(eslint@8.37.0)
eslint-plugin-promise: 6.1.1(eslint@8.37.0)
transitivePeerDependencies:
- supports-color
dev: true
transitivePeerDependencies:
- supports-color
dev: true
- /eslint-config-standard-with-typescript@34.0.1(@typescript-eslint/eslint-plugin@5.57.1)(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)(typescript@5.0.3):
+ /eslint-config-standard-with-typescript@34.0.1(@typescript-eslint/eslint-plugin@5.57.1)(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)(typescript@5.0.4):
resolution: {integrity: sha512-J7WvZeLtd0Vr9F+v4dZbqJCLD16cbIy4U+alJMq4MiXdpipdBM3U5NkXaGUjePc4sb1ZE01U9g6VuTBpHHz1fg==}
peerDependencies:
'@typescript-eslint/eslint-plugin': ^5.43.0
resolution: {integrity: sha512-J7WvZeLtd0Vr9F+v4dZbqJCLD16cbIy4U+alJMq4MiXdpipdBM3U5NkXaGUjePc4sb1ZE01U9g6VuTBpHHz1fg==}
peerDependencies:
'@typescript-eslint/eslint-plugin': ^5.43.0
eslint-plugin-promise: ^6.0.0
typescript: '*'
dependencies:
eslint-plugin-promise: ^6.0.0
typescript: '*'
dependencies:
- '@typescript-eslint/eslint-plugin': 5.57.1(@typescript-eslint/parser@5.57.1)(eslint@8.37.0)(typescript@5.0.3)
- '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.3)
+ '@typescript-eslint/eslint-plugin': 5.57.1(@typescript-eslint/parser@5.57.1)(eslint@8.37.0)(typescript@5.0.4)
+ '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.4)
eslint: 8.37.0
eslint-config-standard: 17.0.0(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)
eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.57.1)(eslint-import-resolver-typescript@3.5.5)(eslint@8.37.0)
eslint-plugin-n: 15.7.0(eslint@8.37.0)
eslint-plugin-promise: 6.1.1(eslint@8.37.0)
eslint: 8.37.0
eslint-config-standard: 17.0.0(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)
eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.57.1)(eslint-import-resolver-typescript@3.5.5)(eslint@8.37.0)
eslint-plugin-n: 15.7.0(eslint@8.37.0)
eslint-plugin-promise: 6.1.1(eslint@8.37.0)
transitivePeerDependencies:
- supports-color
dev: true
transitivePeerDependencies:
- supports-color
dev: true
eslint-import-resolver-webpack:
optional: true
dependencies:
eslint-import-resolver-webpack:
optional: true
dependencies:
- '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.3)
+ '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.4)
debug: 3.2.7
eslint: 8.37.0
eslint-import-resolver-node: 0.3.7
debug: 3.2.7
eslint: 8.37.0
eslint-import-resolver-node: 0.3.7
'@typescript-eslint/parser':
optional: true
dependencies:
'@typescript-eslint/parser':
optional: true
dependencies:
- '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.3)
+ '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.4)
array-includes: 3.1.6
array.prototype.flat: 1.3.1
array.prototype.flatmap: 1.3.1
array-includes: 3.1.6
array.prototype.flat: 1.3.1
array.prototype.flatmap: 1.3.1
engines: {node: '>= 0.8.0'}
dev: true
engines: {node: '>= 0.8.0'}
dev: true
- /prettier-plugin-organize-imports@3.2.2(prettier@2.8.7)(typescript@5.0.3):
+ /prettier-plugin-organize-imports@3.2.2(prettier@2.8.7)(typescript@5.0.4):
resolution: {integrity: sha512-e97lE6odGSiHonHJMTYC0q0iLXQyw0u5z/PJpvP/3vRy6/Zi9kLBwFAbEGjDzIowpjQv8b+J04PDamoUSQbzGA==}
peerDependencies:
'@volar/vue-language-plugin-pug': ^1.0.4
resolution: {integrity: sha512-e97lE6odGSiHonHJMTYC0q0iLXQyw0u5z/PJpvP/3vRy6/Zi9kLBwFAbEGjDzIowpjQv8b+J04PDamoUSQbzGA==}
peerDependencies:
'@volar/vue-language-plugin-pug': ^1.0.4
optional: true
dependencies:
prettier: 2.8.7
optional: true
dependencies:
prettier: 2.8.7
dev: true
/prettier@2.8.7:
dev: true
/prettier@2.8.7:
engines: {node: '>=8'}
dev: true
engines: {node: '>=8'}
dev: true
- /ts-node@10.9.1(@types/node@18.15.11)(typescript@5.0.3):
+ /ts-node@10.9.1(@types/node@18.15.11)(typescript@5.0.4):
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
hasBin: true
peerDependencies:
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
hasBin: true
peerDependencies:
create-require: 1.1.1
diff: 4.0.2
make-error: 1.3.6
create-require: 1.1.1
diff: 4.0.2
make-error: 1.3.6
v8-compile-cache-lib: 3.0.1
yn: 3.1.1
dev: true
v8-compile-cache-lib: 3.0.1
yn: 3.1.1
dev: true
- /ts-standard@12.0.2(eslint-import-resolver-typescript@3.5.5)(typescript@5.0.3):
+ /ts-standard@12.0.2(eslint-import-resolver-typescript@3.5.5)(typescript@5.0.4):
resolution: {integrity: sha512-XX2wrB9fKKTfBj4yD3ABm9iShzZcS2iWcPK8XzlBvuL20+wMiLgiz/k5tXgZwTaYq5wRhbks1Y9PelhujF/9ag==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
hasBin: true
peerDependencies:
typescript: '*'
dependencies:
resolution: {integrity: sha512-XX2wrB9fKKTfBj4yD3ABm9iShzZcS2iWcPK8XzlBvuL20+wMiLgiz/k5tXgZwTaYq5wRhbks1Y9PelhujF/9ag==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
hasBin: true
peerDependencies:
typescript: '*'
dependencies:
- '@typescript-eslint/eslint-plugin': 5.57.1(@typescript-eslint/parser@5.57.1)(eslint@8.37.0)(typescript@5.0.3)
- '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.3)
+ '@typescript-eslint/eslint-plugin': 5.57.1(@typescript-eslint/parser@5.57.1)(eslint@8.37.0)(typescript@5.0.4)
+ '@typescript-eslint/parser': 5.57.1(eslint@8.37.0)(typescript@5.0.4)
eslint: 8.37.0
eslint-config-standard-jsx: 11.0.0(eslint-plugin-react@7.32.2)(eslint@8.37.0)
eslint: 8.37.0
eslint-config-standard-jsx: 11.0.0(eslint-plugin-react@7.32.2)(eslint@8.37.0)
- eslint-config-standard-with-typescript: 23.0.0(@typescript-eslint/eslint-plugin@5.57.1)(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)(typescript@5.0.3)
+ eslint-config-standard-with-typescript: 23.0.0(@typescript-eslint/eslint-plugin@5.57.1)(eslint-plugin-import@2.27.5)(eslint-plugin-n@15.7.0)(eslint-plugin-promise@6.1.1)(eslint@8.37.0)(typescript@5.0.4)
eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.57.1)(eslint-import-resolver-typescript@3.5.5)(eslint@8.37.0)
eslint-plugin-n: 15.7.0(eslint@8.37.0)
eslint-plugin-promise: 6.1.1(eslint@8.37.0)
eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.57.1)(eslint-import-resolver-typescript@3.5.5)(eslint@8.37.0)
eslint-plugin-n: 15.7.0(eslint@8.37.0)
eslint-plugin-promise: 6.1.1(eslint@8.37.0)
minimist: 1.2.8
pkg-conf: 4.0.0
standard-engine: 15.0.0
minimist: 1.2.8
pkg-conf: 4.0.0
standard-engine: 15.0.0
transitivePeerDependencies:
- eslint-import-resolver-typescript
- eslint-import-resolver-webpack
transitivePeerDependencies:
- eslint-import-resolver-typescript
- eslint-import-resolver-webpack
resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==}
dev: true
resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==}
dev: true
- /tsutils@3.21.0(typescript@5.0.3):
+ /tsutils@3.21.0(typescript@5.0.4):
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
engines: {node: '>= 6'}
peerDependencies:
typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta'
dependencies:
tslib: 1.14.1
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
engines: {node: '>= 6'}
peerDependencies:
typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta'
dependencies:
tslib: 1.14.1
dev: true
/type-check@0.3.2:
dev: true
/type-check@0.3.2:
is-typedarray: 1.0.0
dev: true
is-typedarray: 1.0.0
dev: true
- /typedoc@0.23.28(typescript@5.0.3):
+ /typedoc@0.23.28(typescript@5.0.4):
resolution: {integrity: sha512-9x1+hZWTHEQcGoP7qFmlo4unUoVJLB0H/8vfO/7wqTnZxg4kPuji9y3uRzEu0ZKez63OJAUmiGhUrtukC6Uj3w==}
engines: {node: '>= 14.14'}
hasBin: true
resolution: {integrity: sha512-9x1+hZWTHEQcGoP7qFmlo4unUoVJLB0H/8vfO/7wqTnZxg4kPuji9y3uRzEu0ZKez63OJAUmiGhUrtukC6Uj3w==}
engines: {node: '>= 14.14'}
hasBin: true
marked: 4.3.0
minimatch: 7.4.5
shiki: 0.14.1
marked: 4.3.0
minimatch: 7.4.5
shiki: 0.14.1
- /typescript@5.0.3:
- resolution: {integrity: sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==}
+ /typescript@5.0.4:
+ resolution: {integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==}
engines: {node: '>=12.20'}
hasBin: true
dev: true
engines: {node: '>=12.20'}
hasBin: true
dev: true
export { DynamicClusterPool } from './pools/cluster/dynamic'
export { FixedClusterPool } from './pools/cluster/fixed'
export type { ClusterPoolOptions } from './pools/cluster/fixed'
export { DynamicClusterPool } from './pools/cluster/dynamic'
export { FixedClusterPool } from './pools/cluster/fixed'
export type { ClusterPoolOptions } from './pools/cluster/fixed'
-export type { IPool, PoolEmitter, PoolOptions } from './pools/pool'
+export { PoolEvents } from './pools/pool'
+export type { IPool, PoolEmitter, PoolOptions, PoolEvent } from './pools/pool'
export type {
ErrorHandler,
ExitHandler,
export type {
ErrorHandler,
ExitHandler,
import type { MessageValue, PromiseResponseWrapper } from '../utility-types'
import { EMPTY_FUNCTION } from '../utils'
import { KillBehaviors, isKillBehavior } from '../worker/worker-options'
import type { MessageValue, PromiseResponseWrapper } from '../utility-types'
import { EMPTY_FUNCTION } from '../utils'
import { KillBehaviors, isKillBehavior } from '../worker/worker-options'
-import type { PoolOptions } from './pool'
+import { PoolEvents, type PoolOptions } from './pool'
import { PoolEmitter } from './pool'
import type { IPoolInternal, TasksUsage, WorkerType } from './pool-internal'
import { PoolType } from './pool-internal'
import { PoolEmitter } from './pool'
import type { IPoolInternal, TasksUsage, WorkerType } from './pool-internal'
import { PoolType } from './pool-internal'
private checkPoolOptions (opts: PoolOptions<Worker>): void {
this.opts.workerChoiceStrategy =
opts.workerChoiceStrategy ?? WorkerChoiceStrategies.ROUND_ROBIN
private checkPoolOptions (opts: PoolOptions<Worker>): void {
this.opts.workerChoiceStrategy =
opts.workerChoiceStrategy ?? WorkerChoiceStrategies.ROUND_ROBIN
- if (
- !Object.values(WorkerChoiceStrategies).includes(
- this.opts.workerChoiceStrategy
- )
- ) {
+ this.checkValidWorkerChoiceStrategy(this.opts.workerChoiceStrategy)
+ this.opts.enableEvents = opts.enableEvents ?? true
+ }
+
+ private checkValidWorkerChoiceStrategy (
+ workerChoiceStrategy: WorkerChoiceStrategy
+ ): void {
+ if (!Object.values(WorkerChoiceStrategies).includes(workerChoiceStrategy)) {
- `Invalid worker choice strategy '${this.opts.workerChoiceStrategy}'`
+ `Invalid worker choice strategy '${workerChoiceStrategy}'`
- this.opts.enableEvents = opts.enableEvents ?? true
public setWorkerChoiceStrategy (
workerChoiceStrategy: WorkerChoiceStrategy
): void {
public setWorkerChoiceStrategy (
workerChoiceStrategy: WorkerChoiceStrategy
): void {
+ this.checkValidWorkerChoiceStrategy(workerChoiceStrategy)
this.opts.workerChoiceStrategy = workerChoiceStrategy
for (const [index, workerItem] of this.workers.entries()) {
this.setWorker(index, workerItem.worker, {
this.opts.workerChoiceStrategy = workerChoiceStrategy
for (const [index, workerItem] of this.workers.entries()) {
this.setWorker(index, workerItem.worker, {
++workerTasksUsage.error
}
if (this.workerChoiceStrategyContext.getRequiredStatistics().runTime) {
++workerTasksUsage.error
}
if (this.workerChoiceStrategyContext.getRequiredStatistics().runTime) {
- workerTasksUsage.runTime += message.taskRunTime ?? 0
+ workerTasksUsage.runTime += message.runTime ?? 0
if (
this.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime &&
workerTasksUsage.run !== 0
if (
this.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime &&
workerTasksUsage.run !== 0
(message.kill != null &&
this.getWorkerTasksUsage(createdWorker)?.running === 0)
) {
(message.kill != null &&
this.getWorkerTasksUsage(createdWorker)?.running === 0)
) {
- // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime)
+ // Kill message received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime)
void this.destroyWorker(createdWorker)
}
})
void this.destroyWorker(createdWorker)
}
})
protected workerListener (): (message: MessageValue<Response>) => void {
return message => {
if (message.id != null) {
protected workerListener (): (message: MessageValue<Response>) => void {
return message => {
if (message.id != null) {
+ // Task response received
const promiseResponse = this.promiseResponseMap.get(message.id)
if (promiseResponse != null) {
if (message.error != null) {
const promiseResponse = this.promiseResponseMap.get(message.id)
if (promiseResponse != null) {
if (message.error != null) {
private checkAndEmitBusy (): void {
if (this.opts.enableEvents === true && this.busy) {
private checkAndEmitBusy (): void {
if (this.opts.enableEvents === true && this.busy) {
- this.emitter?.emit('busy')
+ this.emitter?.emit(PoolEvents.busy)
this.opts.enableEvents === true &&
this.full
) {
this.opts.enableEvents === true &&
this.full
) {
- this.emitter?.emit('full')
+ this.emitter?.emit(PoolEvents.full)
*/
export class PoolEmitter extends EventEmitter {}
*/
export class PoolEmitter extends EventEmitter {}
+/**
+ * Enumeration of pool events.
+ */
+export const PoolEvents = Object.freeze({
+ full: 'full',
+ busy: 'busy'
+} as const)
+
+/**
+ * Pool event.
+ */
+export type PoolEvent = keyof typeof PoolEvents
+
/**
* Options for a poolifier pool.
*/
/**
* Options for a poolifier pool.
*/
public setWorkerChoiceStrategy (
workerChoiceStrategy: WorkerChoiceStrategy
): void {
public setWorkerChoiceStrategy (
workerChoiceStrategy: WorkerChoiceStrategy
): void {
- if (this.workerChoiceStrategyType === workerChoiceStrategy) {
- this.workerChoiceStrategies.get(workerChoiceStrategy)?.reset()
- } else {
+ if (this.workerChoiceStrategyType !== workerChoiceStrategy) {
this.workerChoiceStrategyType = workerChoiceStrategy
}
this.workerChoiceStrategyType = workerChoiceStrategy
}
+ this.workerChoiceStrategies.get(this.workerChoiceStrategyType)?.reset()
*/
readonly error?: string
/**
*/
readonly error?: string
/**
- readonly taskRunTime?: number
+ readonly runTime?: number
/**
* Reference to main worker.
*
/**
* Reference to main worker.
*
*/
protected lastTaskTimestamp!: number
/**
*/
protected lastTaskTimestamp!: number
/**
- * Handler Id of the `aliveInterval` worker alive check.
+ * Handler id of the `aliveInterval` worker alive check.
*/
protected readonly aliveInterval?: NodeJS.Timeout
/**
*/
protected readonly aliveInterval?: NodeJS.Timeout
/**
protected mainWorker: MainWorker | undefined | null,
protected readonly opts: WorkerOptions = {
/**
protected mainWorker: MainWorker | undefined | null,
protected readonly opts: WorkerOptions = {
/**
- * The kill behavior option on this Worker or its default value.
+ * The kill behavior option on this worker or its default value.
*/
killBehavior: DEFAULT_KILL_BEHAVIOR,
/**
*/
killBehavior: DEFAULT_KILL_BEHAVIOR,
/**
this.checkAlive.bind(this)()
}
this.checkAlive.bind(this)()
}
- this.mainWorker?.on('message', (value: MessageValue<Data, MainWorker>) => {
- this.messageListener(value, fn)
- })
+ this.mainWorker?.on(
+ 'message',
+ (message: MessageValue<Data, MainWorker>) => {
+ this.messageListener(message, fn)
+ }
+ )
+ /**
+ * Worker message listener.
+ *
+ * @param message - Message received.
+ * @param fn - Function processed by the worker when the pool's `execution` function is invoked.
+ */
protected messageListener (
protected messageListener (
- value: MessageValue<Data, MainWorker>,
+ message: MessageValue<Data, MainWorker>,
fn: (data: Data) => Response
): void {
fn: (data: Data) => Response
): void {
- if (value.data != null && value.id != null) {
- // Here you will receive messages
+ if (message.data != null && message.id != null) {
+ // Task message received
if (this.opts.async === true) {
if (this.opts.async === true) {
- this.runInAsyncScope(this.runAsync.bind(this), this, fn, value)
+ this.runInAsyncScope(this.runAsync.bind(this), this, fn, message)
- this.runInAsyncScope(this.run.bind(this), this, fn, value)
+ this.runInAsyncScope(this.run.bind(this), this, fn, message)
- } else if (value.parent != null) {
- // Save a reference of the main worker to communicate with it
- // This will be received once
- this.mainWorker = value.parent
- } else if (value.kill != null) {
- // Here is time to kill this worker, just clearing the interval
+ } else if (message.parent != null) {
+ // Main worker reference message received
+ this.mainWorker = message.parent
+ } else if (message.kill != null) {
+ // Kill message received
this.aliveInterval != null && clearInterval(this.aliveInterval)
this.emitDestroy()
}
this.aliveInterval != null && clearInterval(this.aliveInterval)
this.emitDestroy()
}
* Runs the given function synchronously.
*
* @param fn - Function that will be executed.
* Runs the given function synchronously.
*
* @param fn - Function that will be executed.
- * @param value - Input data for the given function.
+ * @param message - Input data for the given function.
*/
protected run (
fn: (data?: Data) => Response,
*/
protected run (
fn: (data?: Data) => Response,
- value: MessageValue<Data>
+ message: MessageValue<Data>
- const startTaskTimestamp = Date.now()
- const res = fn(value.data)
- const taskRunTime = Date.now() - startTaskTimestamp
- this.sendToMainWorker({ data: res, id: value.id, taskRunTime })
+ const startTimestamp = Date.now()
+ const res = fn(message.data)
+ const runTime = Date.now() - startTimestamp
+ this.sendToMainWorker({ data: res, id: message.id, runTime })
} catch (e) {
const err = this.handleError(e as Error)
} catch (e) {
const err = this.handleError(e as Error)
- this.sendToMainWorker({ error: err, id: value.id })
+ this.sendToMainWorker({ error: err, id: message.id })
} finally {
!this.isMain && (this.lastTaskTimestamp = Date.now())
}
} finally {
!this.isMain && (this.lastTaskTimestamp = Date.now())
}
* Runs the given function asynchronously.
*
* @param fn - Function that will be executed.
* Runs the given function asynchronously.
*
* @param fn - Function that will be executed.
- * @param value - Input data for the given function.
+ * @param message - Input data for the given function.
*/
protected runAsync (
fn: (data?: Data) => Promise<Response>,
*/
protected runAsync (
fn: (data?: Data) => Promise<Response>,
- value: MessageValue<Data>
+ message: MessageValue<Data>
- const startTaskTimestamp = Date.now()
- fn(value.data)
+ const startTimestamp = Date.now()
+ fn(message.data)
- const taskRunTime = Date.now() - startTaskTimestamp
- this.sendToMainWorker({ data: res, id: value.id, taskRunTime })
+ const runTime = Date.now() - startTimestamp
+ this.sendToMainWorker({ data: res, id: message.id, runTime })
return null
})
.catch(e => {
const err = this.handleError(e as Error)
return null
})
.catch(e => {
const err = this.handleError(e as Error)
- this.sendToMainWorker({ error: err, id: value.id })
+ this.sendToMainWorker({ error: err, id: message.id })
})
.finally(() => {
!this.isMain && (this.lastTaskTimestamp = Date.now())
})
.finally(() => {
!this.isMain && (this.lastTaskTimestamp = Date.now())
const { expect } = require('expect')
const {
const { expect } = require('expect')
const {
WorkerChoiceStrategies
} = require('../../../lib/index')
WorkerChoiceStrategies
} = require('../../../lib/index')
)
const promises = []
let poolFull = 0
)
const promises = []
let poolFull = 0
- pool.emitter.on('full', () => ++poolFull)
+ pool.emitter.on(PoolEvents.full, () => ++poolFull)
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.push(pool.execute())
}
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.push(pool.execute())
}
)
const promises = []
let poolBusy = 0
)
const promises = []
let poolBusy = 0
- pool.emitter.on('busy', () => ++poolBusy)
+ pool.emitter.on(PoolEvents.busy, () => ++poolBusy)
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.push(pool.execute())
}
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.push(pool.execute())
}
const { expect } = require('expect')
const { expect } = require('expect')
-const { DynamicClusterPool } = require('../../../lib/index')
+const { DynamicClusterPool, PoolEvents } = require('../../../lib/index')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
it('Verify that new workers are created when required, max size is not exceeded and that after a while new workers will die', async () => {
let poolBusy = 0
it('Verify that new workers are created when required, max size is not exceeded and that after a while new workers will die', async () => {
let poolBusy = 0
- pool.emitter.on('busy', () => ++poolBusy)
+ pool.emitter.on(PoolEvents.busy, () => ++poolBusy)
for (let i = 0; i < max * 2; i++) {
pool.execute()
}
for (let i = 0; i < max * 2; i++) {
pool.execute()
}
const { expect } = require('expect')
const { expect } = require('expect')
-const { FixedClusterPool } = require('../../../lib/index')
+const { FixedClusterPool, PoolEvents } = require('../../../lib/index')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
expect(result).toBe(false)
})
expect(result).toBe(false)
})
- it('Verify that busy event is emitted', async () => {
+ it("Verify that 'busy' event is emitted", async () => {
- pool.emitter.on('busy', () => ++poolBusy)
+ pool.emitter.on(PoolEvents.busy, () => ++poolBusy)
for (let i = 0; i < numberOfWorkers * 2; i++) {
pool.execute()
}
for (let i = 0; i < numberOfWorkers * 2; i++) {
pool.execute()
}
const { expect } = require('expect')
const { expect } = require('expect')
-const { DynamicThreadPool } = require('../../../lib/index')
+const { DynamicThreadPool, PoolEvents } = require('../../../lib/index')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
it('Verify that new workers are created when required, max size is not exceeded and that after a while new workers will die', async () => {
let poolBusy = 0
it('Verify that new workers are created when required, max size is not exceeded and that after a while new workers will die', async () => {
let poolBusy = 0
- pool.emitter.on('busy', () => ++poolBusy)
+ pool.emitter.on(PoolEvents.busy, () => ++poolBusy)
for (let i = 0; i < max * 2; i++) {
pool.execute()
}
for (let i = 0; i < max * 2; i++) {
pool.execute()
}
const { expect } = require('expect')
const { expect } = require('expect')
-const { FixedThreadPool } = require('../../../lib/index')
+const { FixedThreadPool, PoolEvents } = require('../../../lib/index')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
expect(result).toBe(false)
})
expect(result).toBe(false)
})
- it('Verify that busy event is emitted', async () => {
+ it("Verify that 'busy' event is emitted", async () => {
- pool.emitter.on('busy', () => ++poolBusy)
+ pool.emitter.on(PoolEvents.busy, () => ++poolBusy)
for (let i = 0; i < numberOfThreads * 2; i++) {
pool.execute()
}
for (let i = 0; i < numberOfThreads * 2; i++) {
pool.execute()
}