Skip to content

Commit b4e71e0

Browse files
authored
Merge pull request #40 from Cysharp/feature/FixRoundRobinOrder
Fix to retrieve from the beginning of the pool
2 parents 68155a5 + 16f8917 commit b4e71e0

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/LogicLooper/RoundRobinLogicLooperPoolBalancer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class RoundRobinLogicLooperPoolBalancer : ILogicLooperPoolBalancer
44
{
5-
private int _index = 0;
5+
private int _index = -1;
66

77
public static ILogicLooperPoolBalancer Instance { get; } = new RoundRobinLogicLooperPoolBalancer();
88

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Cysharp.Threading;
2+
3+
namespace LogicLooper.Test;
4+
5+
public class RoundRobinLogicLooperPoolBalancerTest
6+
{
7+
[Fact]
8+
public void GetPooledLooper_ReturnsLoopersInRoundRobinOrder()
9+
{
10+
var balancer = RoundRobinLogicLooperPoolBalancer.Instance;
11+
var loopers = new ILogicLooper[]
12+
{
13+
new ManualLogicLooper(1),
14+
new ManualLogicLooper(2),
15+
new ManualLogicLooper(3)
16+
};
17+
Assert.Equal(loopers[0], balancer.GetPooledLooper(loopers));
18+
Assert.Equal(loopers[1], balancer.GetPooledLooper(loopers));
19+
Assert.Equal(loopers[2], balancer.GetPooledLooper(loopers));
20+
Assert.Equal(loopers[0], balancer.GetPooledLooper(loopers));
21+
}
22+
}

0 commit comments

Comments
 (0)