X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fabstract-worker.ts;h=060fe63451877a96c0f26fe843c16ef2c7644f59;hb=896624ae5d3cb6861b202a4c3b1d4c42368868c5;hp=e10521fcbc7808eeffeb778aa8dfb13ce0eb680e;hpb=97cf8c0ddbe1fdba4fde9f94e5b781eeec4d71b5;p=poolifier.git diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index e10521fc..060fe634 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -405,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}` ) @@ -493,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, @@ -505,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 {