refactor: use object destructuration for task execution response
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 17 Nov 2023 20:11:03 +0000 (21:11 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 17 Nov 2023 20:11:03 +0000 (21:11 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts

index b09b81aee096065eed5d5582a117d05eea6e7e8f..94902356f44a7ac180b1282bdeeda70590a39a01 100644 (file)
@@ -1585,13 +1585,13 @@ export abstract class AbstractPool<
     const { taskId, workerError, data } = message
     const promiseResponse = this.promiseResponseMap.get(taskId as string)
     if (promiseResponse != null) {
+      const { resolve, reject, workerNodeKey } = promiseResponse
       if (workerError != null) {
         this.emitter?.emit(PoolEvents.taskError, workerError)
-        promiseResponse.reject(workerError.message)
+        reject(workerError.message)
       } else {
-        promiseResponse.resolve(data as Response)
+        resolve(data as Response)
       }
-      const workerNodeKey = promiseResponse.workerNodeKey
       this.afterTaskExecutionHook(workerNodeKey, message)
       this.workerChoiceStrategyContext.update(workerNodeKey)
       this.promiseResponseMap.delete(taskId as string)