From: Jérôme Benoit Date: Mon, 11 Dec 2023 15:23:53 +0000 (+0100) Subject: perf: convert to arrow function tasks execution code path X-Git-Tag: v3.0.11~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=803f948f302ce93b89b93b875bef173f2a87c5fc;p=poolifier.git perf: convert to arrow function tasks execution code path Signed-off-by: Jérôme Benoit --- diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index ae95dcf8..dfcadf28 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -481,7 +481,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)) { @@ -509,10 +509,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) @@ -543,10 +543,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) diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index cafef7fc..d972692e 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -59,7 +59,9 @@ export class ClusterWorker< } /** @inheritDoc */ - protected sendToMainWorker (message: MessageValue): void { + protected readonly sendToMainWorker = ( + message: MessageValue + ): void => { this.getMainWorker().send({ ...message, workerId: this.id }) } } diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index 756550e3..e133430f 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -80,7 +80,9 @@ export class ThreadWorker< } /** @inheritDoc */ - protected sendToMainWorker (message: MessageValue): void { + protected readonly sendToMainWorker = ( + message: MessageValue + ): void => { this.port?.postMessage({ ...message, workerId: this.id }) }