Skip to content

Commit

Permalink
Add comments and better variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 committed Sep 20, 2016
1 parent f5e0b62 commit 8405bbe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions peer.go
Expand Up @@ -346,6 +346,7 @@ func (p *Peer) GetConnection(ctx context.Context) (*Connection, error) {
return activeConn, nil
}

// Lock here to restrict new connection creation attempts to one goroutine
p.newConnLock.Lock()
defer p.newConnLock.Unlock()

Expand Down
4 changes: 2 additions & 2 deletions peer_test.go
Expand Up @@ -201,11 +201,11 @@ func TestPeerGetConnectionWithNoActiveConnections(t *testing.T) {
wg sync.WaitGroup
lock sync.Mutex
conn *Connection
numRequests = 10
concurrency = 10
p = client.Peers().Add(hostPort)
)

for i := 0; i < numRequests; i++ {
for i := 0; i < concurrency; i++ {
wg.Add(1)
go func() {
defer wg.Done()
Expand Down

0 comments on commit 8405bbe

Please sign in to comment.