- /** {@inheritDoc} */
- public remove (workerKey: number): boolean {
- if (this.nextWorkerId === workerKey) {
- this.nextWorkerId =
- this.nextWorkerId > this.pool.workers.length - 1
- ? this.pool.workers.length - 1
- : this.nextWorkerId
+ /** @inheritDoc */
+ public choose (): number | undefined {
+ const chosenWorkerNodeKey = this.nextWorkerNodeKey
+ this.roundRobinNextWorkerNodeKey()
+ if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) {
+ this.nextWorkerNodeKey = undefined
+ }
+ return chosenWorkerNodeKey
+ }
+
+ /** @inheritDoc */
+ public remove (workerNodeKey: number): boolean {
+ if (this.nextWorkerNodeKey === workerNodeKey) {
+ if (this.pool.workerNodes.length === 0) {
+ this.nextWorkerNodeKey = 0
+ } else if (this.nextWorkerNodeKey > this.pool.workerNodes.length - 1) {
+ this.nextWorkerNodeKey = this.pool.workerNodes.length - 1
+ }