refactor: remove unneeded condition in task stealing code
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 25 Aug 2023 16:28:06 +0000 (18:28 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 25 Aug 2023 16:28:06 +0000 (18:28 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/worker-node.ts

index e28372efa1b3c73cf9c8904d6077f87fed1dd553..9ecfd012f9b5402c4676004f24f7c04ecc4bf020 100644 (file)
@@ -178,16 +178,14 @@ implements IWorkerNode<Worker, Data> {
   }
 
   private async startOnEmptyQueue (): Promise<void> {
-    if (this.onEmptyQueue != null) {
-      if (this.tasksQueue.size > 0) {
-        this.onEmptyQueueCount = 0
-        return
-      }
-      this.onEmptyQueue(this.info.id as number)
-      ++this.onEmptyQueueCount
-      await sleep(exponentialDelay(this.onEmptyQueueCount))
-      await this.startOnEmptyQueue()
+    if (this.tasksQueue.size > 0) {
+      this.onEmptyQueueCount = 0
+      return
     }
+    (this.onEmptyQueue as (workerId: number) => void)(this.info.id as number)
+    ++this.onEmptyQueueCount
+    await sleep(exponentialDelay(this.onEmptyQueueCount))
+    await this.startOnEmptyQueue()
   }
 
   private initWorkerInfo (worker: Worker, workerType: WorkerType): WorkerInfo {