From: Jérôme Benoit Date: Thu, 4 May 2023 21:08:30 +0000 (+0200) Subject: refactor: factor out code to get worker function X-Git-Tag: v2.4.12~15^2~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c7c046988e2b4d93ce7998ebf39e5ad5ab92fec1;p=poolifier.git refactor: factor out code to get worker function Signed-off-by: Jérôme Benoit --- 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 {