X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fabstract-worker.ts;h=060fe63451877a96c0f26fe843c16ef2c7644f59;hb=refs%2Ftags%2Fv3.0.6;hp=311a56ad60e00684835e89ef0507d60f0c9d4432;hpb=9a38f99e676160c0bc7d28fe88f27b01fa31b5a1;p=poolifier.git diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 311a56ad..060fe634 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -100,6 +100,7 @@ export abstract class AbstractWorker< this.checkTaskFunctions(taskFunctions) this.checkWorkerOptions(this.opts) if (!this.isMain) { + // Should be once() but Node.js on windows has a bug that prevents it from working this.getMainWorker().on('message', this.handleReadyMessage.bind(this)) } } @@ -367,13 +368,13 @@ export abstract class AbstractWorker< * * @param message - The kill message. */ - protected handleKillMessage (message: MessageValue): void { + protected handleKillMessage (_message: MessageValue): void { this.stopCheckActive() if (isAsyncFunction(this.opts.killHandler)) { (this.opts.killHandler?.() as Promise) .then(() => { this.sendToMainWorker({ kill: 'success' }) - return null + return undefined }) .catch(() => { this.sendToMainWorker({ kill: 'failure' }) @@ -404,7 +405,7 @@ export abstract class AbstractWorker< private checkMessageWorkerId (message: MessageValue): void { if (message.workerId == null) { throw new Error('Message worker id is not set') - } else if (message.workerId != null && message.workerId !== this.id) { + } else if (message.workerId !== this.id) { throw new Error( `Message worker id ${message.workerId} does not match the worker id ${this.id}` ) @@ -492,8 +493,8 @@ export abstract class AbstractWorker< */ protected run (task: Task): void { const { name, taskId, data } = task - const fn = this.taskFunctions.get(name ?? DEFAULT_TASK_NAME) - if (fn == null) { + const taskFunctionName = name ?? DEFAULT_TASK_NAME + if (!this.taskFunctions.has(taskFunctionName)) { this.sendToMainWorker({ workerError: { name: name as string, @@ -504,6 +505,7 @@ export abstract class AbstractWorker< }) return } + const fn = this.taskFunctions.get(taskFunctionName) if (isAsyncFunction(fn)) { this.runInAsyncScope(this.runAsync.bind(this), this, fn, task) } else {