From c7c046988e2b4d93ce7998ebf39e5ad5ab92fec1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 4 May 2023 23:08:30 +0200 Subject: [PATCH] refactor: factor out code to get worker function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/index.ts | 5 +++-- src/utility-types.ts | 2 +- src/worker/abstract-worker.ts | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index d1482c83..0c948c84 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,8 +6,8 @@ export { PoolEvents } from './pools/pool' export type { IPool, PoolEmitter, - PoolOptions, PoolEvent, + PoolOptions, PoolType, TasksQueueOptions } from './pools/pool' @@ -39,8 +39,9 @@ export { KillBehaviors } from './worker/worker-options' export type { KillBehavior, WorkerOptions } from './worker/worker-options' export type { Draft, - PromiseResponseWrapper, MessageValue, + PromiseResponseWrapper, + TaskFunctions, WorkerAsyncFunction, WorkerFunction, WorkerSyncFunction diff --git a/src/utility-types.ts b/src/utility-types.ts index 54494354..54e66e1b 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -69,7 +69,7 @@ export type WorkerFunction = | WorkerSyncFunction | WorkerAsyncFunction /** - * Worker functions object that can be executed. + * Worker functions that can be executed object. * This object can contain synchronous or asynchronous functions. * The key is the name of the function. * The value is the function itself. diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 0c6d1ac3..2aca9e91 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -143,8 +143,8 @@ export abstract class AbstractWorker< */ protected messageListener (message: MessageValue): void { if (message.id != null && message.data != null) { - const fn = this.getTaskFunction(message.name) // Task message received + const fn = this.getTaskFunction(message.name) if (fn?.constructor.name === 'AsyncFunction') { this.runInAsyncScope(this.runAsync.bind(this), this, fn, message) } else { -- 2.34.1