refactor: factor out code to get worker function
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 4 May 2023 21:08:30 +0000 (23:08 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 4 May 2023 21:08:30 +0000 (23:08 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/index.ts
src/utility-types.ts
src/worker/abstract-worker.ts

index d1482c8336aa0bfc755217ac015a58f2766af0e4..0c948c847b6bb974253e4c421e640a95b5bc5fd7 100644 (file)
@@ -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
index 5449435478a202608ad9eed8590f8a77a5ba2d1f..54e66e1bbe9432c1c23c2851ca0466486d5efed5 100644 (file)
@@ -69,7 +69,7 @@ export type WorkerFunction<Data = unknown, Response = unknown> =
   | WorkerSyncFunction<Data, Response>
   | WorkerAsyncFunction<Data, Response>
 /**
- * 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.
index 0c6d1ac3cec4c087622c3d1b1887da4ace4c4f84..2aca9e914b2f4f296624f842ccbee9e159790815 100644 (file)
@@ -143,8 +143,8 @@ export abstract class AbstractWorker<
    */
   protected messageListener (message: MessageValue<Data, MainWorker>): 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 {