X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fabstract-worker.ts;h=107d72384166053e5783f121ef14d0a7abbe69ca;hb=e81c38f2f8046e9a482e94040b8f6d31dcda160c;hp=1b64dc4f4cfff7c769ade8ef2bbd100efa1885ab;hpb=c172526cd82999efbace45402e0bd6d9ae173963;p=poolifier.git diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 1b64dc4f..107d7238 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -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