refactor: cleanup task functions handling
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 19 Nov 2023 20:23:16 +0000 (21:23 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 19 Nov 2023 20:23:16 +0000 (21:23 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/worker/abstract-worker.ts

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