Hacker News new | ask | show | jobs
by shurcooL 4704 days ago

  A channel may be closed with the built-in function close; the multi-valued
  assignment form of the receive operator tests whether a channel has been closed. [1]
Given that is available, why is the use of a separate bool quit channel preferred?

[1] http://golang.org/ref/spec#Channel_types

2 comments

In the link, the quit is acknowledged, so one side closing the channel straight off the bat wouldn't allow for that.
A quit channel (that is not receive only) can be used to send back a quit message by a goroutine that only has a receive-only view of the main data channel; close() can't be called on a receive-only channel.