Skip to content

Commit

Permalink
Merge pull request #6 from utopia-php/fix-round-robin
Browse files Browse the repository at this point in the history
Fix round robin index
  • Loading branch information
TorstenDittmann authored Nov 8, 2022
2 parents 110e1f1 + af53604 commit 1137448
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Balancer/Algorithm/RoundRobin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ public function run(array $options): ?Option
{
$this->index++;

$keys = \array_keys($options);
$option = null;

if (\count($options) === $this->index) {
$option = $options[$keys[0]];
$option = $options[0];
$this->index = 0;
} else {
$option = $options[$keys[$this->index]];
$option = $options[$this->index];
}

return $option;
Expand Down
2 changes: 2 additions & 0 deletions src/Balancer/Balancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function run(): ?Option
$options = \array_filter($options, $filter);
}

$options = \array_values($options);

return $this->algo->run($options);
}
}

0 comments on commit 1137448

Please sign in to comment.