←back to thread

159 points mpweiher | 1 comments | | HN request time: 0.279s | source
Show context
ricardobeat ◴[] No.43671958[source]
Strange to go all this length without mentioning the approaches that solve the problem in that first example:

1. send a close message on the channel that stops the goroutine

2. use a Context instance - `ctx.Done()` returns a channel you can select on

Both are quite easy to grasp and implement.

replies(2): >>43671984 #>>43672081 #
sapiogram ◴[] No.43672081[source]
You've misunderstood the example. The `scores` channel aggregates scores from all players, you can't close it just because one player leaves.

I'd really, really recommend that you try writing the code, like the post encourages. It's so much harder than it looks, which neatly sums up my overall experience with Go channels.

replies(3): >>43672616 #>>43673034 #>>43673193 #
1. ◴[] No.43673034[source]