refactor: cleanup task function default name handling
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 22 Nov 2023 08:50:43 +0000 (09:50 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 22 Nov 2023 08:50:43 +0000 (09:50 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/worker/abstract-worker.ts

index 5c1785f2b1c92c7843fb923e6763476c8f58e080..060fe63451877a96c0f26fe843c16ef2c7644f59 100644 (file)
@@ -493,7 +493,8 @@ export abstract class AbstractWorker<
    */
   protected run (task: Task<Data>): void {
     const { name, taskId, data } = task
-    if (!this.taskFunctions.has(name ?? DEFAULT_TASK_NAME)) {
+    const taskFunctionName = name ?? DEFAULT_TASK_NAME
+    if (!this.taskFunctions.has(taskFunctionName)) {
       this.sendToMainWorker({
         workerError: {
           name: name as string,
@@ -504,7 +505,7 @@ export abstract class AbstractWorker<
       })
       return
     }
-    const fn = this.taskFunctions.get(name ?? DEFAULT_TASK_NAME)
+    const fn = this.taskFunctions.get(taskFunctionName)
     if (isAsyncFunction(fn)) {
       this.runInAsyncScope(this.runAsync.bind(this), this, fn, task)
     } else {