* @throws {@link https://nodejs.org/api/errors.html#class-error} If the worker id is invalid.
*/
private checkMessageWorkerId (message: MessageValue<Response>): void {
- if (
+ if (message.workerId == null) {
+ throw new Error('Worker message received without worker id')
+ } else if (
message.workerId != null &&
this.getWorkerNodeKeyByWorkerId(message.workerId) === -1
) {
typeof name === 'string' &&
name.trim().length === 0
) {
- reject(new Error('name argument must not be an empty string'))
+ reject(new TypeError('name argument must not be an empty string'))
}
- if (name != null && !this.taskFunctions.includes(name)) {
+ if (
+ name != null &&
+ this.taskFunctions != null &&
+ !this.taskFunctions.includes(name)
+ ) {
reject(
new Error(`Task function '${name}' is not registered in the pool`)
)
await this.destroyWorkerNode(workerNodeKey)
})
)
+ this.emitter?.emit(PoolEvents.destroy)
}
protected async sendKillMessageToWorker (
protected createAndSetupWorkerNode (): number {
const worker = this.createWorker()
+ 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) => {
this.redistributeQueuedTasks(workerNodeKey)
}
})
- worker.on('online', this.opts.onlineHandler ?? EMPTY_FUNCTION)
worker.on('exit', this.opts.exitHandler ?? EMPTY_FUNCTION)
worker.once('exit', () => {
this.removeWorkerNode(worker)