X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fabstract-pool.ts;h=18d4fb8362dcfdd9de125e0e83ca51aa91b98ff3;hb=8f49716c05eb5a286c715089e5ec07f030c9cde8;hp=5b2bd15012142fa7e075fa8ea4968041ccfdd63a;hpb=90d7d101196cf9702ccc1d220dd33cca67a427b0;p=poolifier.git diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 5b2bd150..18d4fb83 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -510,7 +510,9 @@ export abstract class AbstractPool< * @throws {@link https://nodejs.org/api/errors.html#class-error} If the worker id is invalid. */ private checkMessageWorkerId (message: MessageValue): 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 ) { @@ -670,9 +672,13 @@ export abstract class AbstractPool< 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`) ) @@ -717,6 +723,7 @@ export abstract class AbstractPool< await this.destroyWorkerNode(workerNodeKey) }) ) + this.emitter?.emit(PoolEvents.destroy) } protected async sendKillMessageToWorker ( @@ -928,6 +935,7 @@ export abstract class AbstractPool< 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) => { @@ -947,7 +955,6 @@ export abstract class AbstractPool< 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)