X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fabstract-worker.ts;h=e2b16e25495eafb6a70a8e50ac2fa0e208583d0e;hb=498900302ba93560b59953a7da4be695986f89bc;hp=5fcc3419b2c1acc8d9ea39ca556c199a9ff44ea9;hpb=69b70a7e1d5238ebb186171275941ec4bcffc882;p=poolifier.git diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 5fcc3419..e2b16e25 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -76,23 +76,21 @@ export abstract class AbstractWorker< * Handler id of the `activeInterval` worker activity check. */ protected activeInterval?: NodeJS.Timeout + /** * Constructs a new poolifier worker. * - * @param type - The type of async event. * @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 opts - Options for the worker. */ public constructor ( - type: string, protected readonly isMain: boolean, private readonly mainWorker: MainWorker, taskFunctions: TaskFunction | TaskFunctions, protected opts: WorkerOptions = DEFAULT_WORKER_OPTIONS ) { - // super(type) if (this.isMain == null) { throw new Error('isMain parameter is mandatory') } @@ -484,7 +482,7 @@ export abstract class AbstractWorker< * * @param task - The task to execute. */ - protected run (task: Task): void { + protected readonly run = (task: Task): void => { const { name, taskId, data } = task const taskFunctionName = name ?? DEFAULT_TASK_NAME if (!this.taskFunctions.has(taskFunctionName)) { @@ -512,10 +510,10 @@ export abstract class AbstractWorker< * @param fn - Task function that will be executed. * @param task - Input data for the task function. */ - protected runSync ( + protected readonly runSync = ( fn: TaskSyncFunction, task: Task - ): void { + ): void => { const { name, taskId, data } = task try { let taskPerformance = this.beginTaskPerformance(name) @@ -546,10 +544,10 @@ export abstract class AbstractWorker< * @param fn - Task function that will be executed. * @param task - Input data for the task function. */ - protected runAsync ( + protected readonly runAsync = ( fn: TaskAsyncFunction, task: Task - ): void { + ): void => { const { name, taskId, data } = task let taskPerformance = this.beginTaskPerformance(name) fn(data)