Simplify worker choosing (#138)
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 13 Feb 2021 10:40:47 +0000 (11:40 +0100)
committerGitHub <noreply@github.com>
Sat, 13 Feb 2021 10:40:47 +0000 (11:40 +0100)
src/pools/abstract-pool.ts

index 1ae188dd53cb2f194e586a0c82087db7f9ed1dc8..1ccaca8b207c613359265eb757d74dffc8c47176 100644 (file)
@@ -150,13 +150,9 @@ export abstract class AbstractPool<
   }
 
   protected chooseWorker (): Worker {
-    if (this.workers.length - 1 === this.nextWorker) {
-      this.nextWorker = 0
-      return this.workers[this.nextWorker]
-    } else {
-      this.nextWorker++
-      return this.workers[this.nextWorker]
-    }
+    this.nextWorker =
+      this.nextWorker === this.workers.length - 1 ? 0 : this.nextWorker + 1
+    return this.workers[this.nextWorker]
   }
 
   protected abstract newWorker (): Worker