Skip to content

Commit c51abc7

Browse files
author
William Kennedy
committed
Fixing closure bug
1 parent b76a0c5 commit c51abc7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

topics/channels/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ Write a program where two goroutines pass an integer back and forth ten times. D
4848
Write a program that uses a buffered channel to maintain a buffer of four strings. In main, send the strings 'A', 'B', 'C' and 'D' into the channel. Then create 20 goroutines that receive a string from the channel, display the value and then send the string back into the channel. Once each goroutine is done performing that task, allow the goroutine to terminate.
4949

5050
[Template](exercises/template2/template2.go) ([Go Playground](https://play.golang.org/p/Ki3X_YIny6)) |
51-
[Answer](exercises/exercise2/exercise2.go) ([Go Playground](https://play.golang.org/p/YPAwHnkNcJ))
51+
[Answer](exercises/exercise2/exercise2.go) ([Go Playground](https://play.golang.org/p/CA-t-2ty1x))
5252
___
5353
All material is licensed under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0).

topics/channels/exercises/exercise2/exercise2.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// All material is licensed under the Apache License Version 2.0, January 2004
22
// http://www.apache.org/licenses/LICENSE-2.0
33

4-
// https://play.golang.org/p/YPAwHnkNcJ
4+
// https://play.golang.org/p/CA-t-2ty1x
55

66
// Write a problem that uses a buffered channel to maintain a buffer
77
// of four strings. In main, send the strings 'A', 'B', 'C' and 'D'
@@ -32,10 +32,10 @@ func main() {
3232
// Launch goroutines to handle the work.
3333
wg.Add(goroutines)
3434
for gr := 1; gr <= goroutines; gr++ {
35-
go func() {
35+
go func(gr int) {
3636
worker(gr)
3737
wg.Done()
38-
}()
38+
}(gr)
3939
}
4040

4141
// Add the strings.

0 commit comments

Comments
 (0)