fix: workaround race conditions at pool destroy
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 14 Aug 2024 18:22:32 +0000 (20:22 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 14 Aug 2024 18:22:32 +0000 (20:22 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts

index 8aab6695ed2a241aaaec11cada85b3567eb312c2..a1b6b02e062da9ef12fa1c24dd3a05ef96ebed39 100644 (file)
@@ -2163,7 +2163,9 @@ export abstract class AbstractPool<
           })
         }
       }
-      workerNode.emit('taskFinished', taskId)
+      // FIXME: cannot be theoretically undefined. Schedule in the next tick to avoid race conditions?
+      // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+      workerNode?.emit('taskFinished', taskId)
     }
   }