Skip to content

Commit 0a50de0

Browse files
changed the q variable to query and fixed comments.
1 parent 80bf500 commit 0a50de0

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎chapter7/patterns/pool/main/main.go‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ func main() {
5656
}
5757

5858
// Perform queries using a connection from the pool.
59-
for q := 0; q < maxGoroutines; q++ {
60-
// TODO: Explain about closures and why we are using params
61-
go func(n int) {
62-
performQueries(n, p)
59+
for query := 0; query < maxGoroutines; query++ {
60+
// Each goroutine needs its own copy of the query
61+
// value else they will all be sharing the same query
62+
// variable.
63+
go func(query int) {
64+
performQueries(query, p)
6365
wg.Done()
64-
}(q)
66+
}(query)
6567

6668
time.Sleep(time.Duration(rand.Intn(500)) * time.Millisecond)
6769
}

0 commit comments

Comments
 (0)