Skip to content

Commit

Permalink
add/remove BalancingClient to be more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
treethought committed Mar 10, 2022
1 parent 624b4e0 commit d076bac
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lbclient.go
Expand Up @@ -92,9 +92,9 @@ func (cc *LBClient) init() {
}
}

// AddClient adds a new HostClient to the balanced clients
// AddClient adds a new client to the balanced clients
// returns the new total number of clients
func (cc *LBClient) AddClient(c *HostClient) int {
func (cc *LBClient) AddClient(c BalancingClient) int {
cc.mu.Lock()
cc.cs = append(cc.cs, &lbClient{
c: c,
Expand All @@ -107,15 +107,10 @@ func (cc *LBClient) AddClient(c *HostClient) int {
// RemoveClients removes clients using the provided callback
// if rc returns true, the passed client will be removed
// returns the new total number of clients
func (cc *LBClient) RemoveClients(rc func(*HostClient) bool) int {
func (cc *LBClient) RemoveClients(rc func(BalancingClient) bool) int {
cc.mu.Lock()
for idx, cs := range cc.cs {
// ignore non HostClient BalancingClients
hc, ok := cs.c.(*HostClient)
if !ok {
continue
}
if rc(hc) {
if rc(cs.c) {
cc.cs = append(cc.cs[:idx], cc.cs[idx+1])
}
}
Expand Down

0 comments on commit d076bac

Please sign in to comment.