fix: properly handle response for add/remove/set task function operaions
[poolifier.git] / src / worker / abstract-worker.ts
index 1b64dc4f4cfff7c769ade8ef2bbd100efa1885ab..107d72384166053e5783f121ef14d0a7abbe69ca 100644 (file)
@@ -18,15 +18,11 @@ import { KillBehaviors, type WorkerOptions } from './worker-options'
 import type {
   TaskAsyncFunction,
   TaskFunction,
+  TaskFunctionOperationReturnType,
   TaskFunctions,
   TaskSyncFunction
 } from './task-functions'
 
-interface TaskFunctionOperationReturnType {
-  status: boolean
-  error?: Error
-}
-
 const DEFAULT_MAX_INACTIVE_TIME = 60000
 const DEFAULT_WORKER_OPTIONS: WorkerOptions = {
   /**
@@ -217,7 +213,7 @@ export abstract class AbstractWorker<
         this.taskFunctions.set(DEFAULT_TASK_NAME, boundFn)
       }
       this.taskFunctions.set(name, boundFn)
-      this.sendTaskFunctionsListToMainWorker()
+      this.sendTaskFunctionNamesToMainWorker()
       return { status: true }
     } catch (error) {
       return { status: false, error: error as Error }
@@ -247,7 +243,7 @@ export abstract class AbstractWorker<
         )
       }
       const deleteStatus = this.taskFunctions.delete(name)
-      this.sendTaskFunctionsListToMainWorker()
+      this.sendTaskFunctionNamesToMainWorker()
       return { status: deleteStatus }
     } catch (error) {
       return { status: false, error: error as Error }
@@ -355,9 +351,7 @@ export abstract class AbstractWorker<
   ): void {
     const { taskFunctionOperation, taskFunction, taskFunctionName } = message
     let response!: TaskFunctionOperationReturnType
-    if (taskFunctionOperation === 'has') {
-      response = this.hasTaskFunction(taskFunctionName as string)
-    } else if (taskFunctionOperation === 'add') {
+    if (taskFunctionOperation === 'add') {
       response = this.addTaskFunction(
         taskFunctionName as string,
         // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
@@ -487,9 +481,9 @@ export abstract class AbstractWorker<
   ): void
 
   /**
-   * Sends the list of task function names to the main worker.
+   * Sends task function names to the main worker.
    */
-  protected sendTaskFunctionsListToMainWorker (): void {
+  protected sendTaskFunctionNamesToMainWorker (): void {
     this.sendToMainWorker({
       taskFunctionNames: this.listTaskFunctionNames(),
       workerId: this.id