From: Jérôme Benoit Date: Tue, 24 Sep 2024 16:44:45 +0000 (+0200) Subject: build(ci): silence linter error X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0fd6ad4619f547ee56218f2ef45ea1a36c4b0dfe;p=poolifier.git build(ci): silence linter error Signed-off-by: Jérôme Benoit --- diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 57f64171..53ec62f9 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -179,7 +179,7 @@ export abstract class AbstractWorker< protected statistics?: WorkerStatistics /** - * Task function object(s) processed by the worker when the pool's `execution` function is invoked. + * Task function object(s) processed by the worker when the pool's `execute` method is invoked. */ protected taskFunctions!: Map> @@ -187,7 +187,7 @@ export abstract class AbstractWorker< * Constructs a new poolifier worker. * @param isMain - Whether this is the main worker or not. * @param mainWorker - Reference to main worker. - * @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked. The first function is the default function. + * @param taskFunctions - Task function(s) processed by the worker when the pool's `execute` method is invoked. The first function is the default function. * @param opts - Options for the worker. */ public constructor ( @@ -272,19 +272,25 @@ export abstract class AbstractWorker< let response: TaskFunctionOperationResult switch (taskFunctionOperation) { case 'add': - response = this.addTaskFunction(taskFunctionProperties.name, { - // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func - taskFunction: new Function( - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - `return ${taskFunction!}` - )() as TaskFunction, - ...(taskFunctionProperties.priority != null && { - priority: taskFunctionProperties.priority, - }), - ...(taskFunctionProperties.strategy != null && { - strategy: taskFunctionProperties.strategy, - }), - }) + if (typeof taskFunction === 'string') { + response = this.addTaskFunction(taskFunctionProperties.name, { + // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func, @typescript-eslint/no-unsafe-call + taskFunction: new Function( + `return ${taskFunction}` + )() as TaskFunction, + ...(taskFunctionProperties.priority != null && { + priority: taskFunctionProperties.priority, + }), + ...(taskFunctionProperties.strategy != null && { + strategy: taskFunctionProperties.strategy, + }), + }) + } else { + response = { + error: new Error("'taskFunction' property is not a string"), + status: false, + } + } break case 'default': response = this.setDefaultTaskFunction(taskFunctionProperties.name) diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index e6ffe0e2..e01e54e5 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -35,7 +35,7 @@ export class ClusterWorker< /** * Constructs a new poolifier cluster worker. - * @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked. + * @param taskFunctions - Task function(s) processed by the worker when the pool's `execute` method is invoked. * @param opts - Options for the worker. */ public constructor ( diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index 85ec8681..82305d3f 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -45,7 +45,7 @@ export class ThreadWorker< /** * Constructs a new poolifier thread worker. - * @param taskFunctions - Task function(s) processed by the worker when the pool's `execution` function is invoked. + * @param taskFunctions - Task function(s) processed by the worker when the pool's `execute` method is invoked. * @param opts - Options for the worker. */ public constructor (