perf: move tasks promise map entry deletion to a micro task
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 26 Oct 2024 20:04:34 +0000 (22:04 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 26 Oct 2024 20:04:34 +0000 (22:04 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts

index eeca65eef1728573c3959fee8ff55353fbf061fc..2d573f6c771daf8279629fe7bdd5bf7b1fb25b24 100644 (file)
@@ -1197,12 +1197,12 @@ export abstract class AbstractPool<
       }
       asyncResource?.emitDestroy()
       this.afterTaskExecutionHook(workerNodeKey, message)
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      this.promiseResponseMap.delete(taskId!)
       queueMicrotask(() => {
         this.checkAndEmitTaskExecutionFinishedEvents()
         // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
         workerNode?.emit('taskFinished', taskId)
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        this.promiseResponseMap.delete(taskId!)
         if (this.opts.enableTasksQueue === true && !this.destroying) {
           if (
             !this.isWorkerNodeBusy(workerNodeKey) &&