### Added
-- Add safe helper `availableParallelism` to help sizing the pool.
+- Add safe helper `availableParallelism()` to help sizing the pool.
### Fixed
### Fixed
- Artificial version bump to 2.6.5 to workaround publication issue.
-- Ensure cluster pool destroy() gracefully shutdowns worker's server.
+- Ensure cluster pool `destroy()` gracefully shutdowns worker's server.
- Ensure pool event is emitted before task error promise rejection.
- Fix queued tasks count computation.
### Fixed
-- Ensure cluster pool destroy() gracefully shutdowns worker's server.
+- Ensure cluster pool `destroy()` gracefully shutdowns worker's server.
- Ensure pool event is emitted before task error promise rejection.
- Fix queued tasks count computation.
* @throws {@link https://nodejs.org/api/errors.html#class-typeerror} If the `name` parameter is not a string or an empty string.
*/
public hasTaskFunction (name: string): boolean {
- if (typeof name !== 'string') {
- throw new TypeError('name parameter is not a string')
- }
- if (typeof name === 'string' && name.trim().length === 0) {
- throw new TypeError('name parameter is an empty string')
- }
+ this.checkTaskFunctionName(name)
return this.taskFunctions.has(name)
}
name: string,
fn: TaskFunction<Data, Response>
): boolean {
- if (typeof name !== 'string') {
- throw new TypeError('name parameter is not a string')
- }
- if (typeof name === 'string' && name.trim().length === 0) {
- throw new TypeError('name parameter is an empty string')
- }
+ this.checkTaskFunctionName(name)
if (name === DEFAULT_TASK_NAME) {
throw new Error(
'Cannot add a task function with the default reserved name'
* @throws {@link https://nodejs.org/api/errors.html#class-error} If the `name` parameter is the task function used as default task function.
*/
public removeTaskFunction (name: string): boolean {
- if (typeof name !== 'string') {
- throw new TypeError('name parameter is not a string')
- }
- if (typeof name === 'string' && name.trim().length === 0) {
- throw new TypeError('name parameter is an empty string')
- }
+ this.checkTaskFunctionName(name)
if (name === DEFAULT_TASK_NAME) {
throw new Error(
'Cannot remove the task function with the default reserved name'
* @throws {@link https://nodejs.org/api/errors.html#class-error} If the `name` parameter is a non-existing task function.
*/
public setDefaultTaskFunction (name: string): boolean {
- if (typeof name !== 'string') {
- throw new TypeError('name parameter is not a string')
- }
- if (typeof name === 'string' && name.trim().length === 0) {
- throw new TypeError('name parameter is an empty string')
- }
+ this.checkTaskFunctionName(name)
if (name === DEFAULT_TASK_NAME) {
throw new Error(
'Cannot set the default task function reserved name as the default task function'
}
}
+ private checkTaskFunctionName (name: string): void {
+ if (typeof name !== 'string') {
+ throw new TypeError('name parameter is not a string')
+ }
+ if (typeof name === 'string' && name.trim().length === 0) {
+ throw new TypeError('name parameter is an empty string')
+ }
+ }
+
/**
* Handles the ready message sent by the main worker.
*