github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/cluster/round_robin.go (about) 1 package cluster 2 3 import "sync/atomic" 4 5 type SimpleRoundRobin struct { 6 val int32 7 m MemberStrategy 8 } 9 10 func NewSimpleRoundRobin(memberStrategy MemberStrategy) *SimpleRoundRobin { 11 return &SimpleRoundRobin{m: memberStrategy} 12 } 13 14 func (r *SimpleRoundRobin) GetByRoundRobin() string { 15 members := r.m.GetAllMembers() 16 l := len(members) 17 if l == 0 { 18 return "" 19 } 20 if l == 1 { 21 return members[0].Address() 22 } 23 nv := atomic.AddInt32(&r.val, 1) 24 return members[int(nv)%l].Address() 25 }