Skip to content

Commit

Permalink
More readable connection collection
Browse files Browse the repository at this point in the history
  • Loading branch information
cnnrznn committed Mar 21, 2024
1 parent 20a5e49 commit 018812d
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions internal/protocol/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,19 @@ func (c *Connector) connectAttemptAll(ctx context.Context, log logging.Func) (*P
}(server, protocolChan)
}

// Read from protocol chan, cancel context\
var protocol *Protocol
for pc := range protocolChan {
if protocol != nil {
pc.Close()
continue
}
protocol = pc
cancel()
// Read from protocol chan, cancel context
protocol, ok := <-protocolChan
if !ok {
return nil, ErrNoAvailableLeader
}

if protocol != nil {
return protocol, nil
cancel()

for extra := range protocolChan {
extra.Close()
}

return nil, ErrNoAvailableLeader
return protocol, nil
}

// Perform the initial handshake using the given protocol version.
Expand Down

0 comments on commit 018812d

Please sign in to comment.