On Tue, Dec 13, 2016 at 10:03 AM, go-question <question.develo...@gmail.com> wrote: > > Whats the reason behind panicking when calling close on a closed channel? > > Receiving on a closed channel returns the zero value. > Wouldn't it be safer to do a no-op and rely on the multivar return to inform > the caller when it is successful? > > Though, maybe the latter point could be confusing with regard to what was > successful, the channel being closed or the operation.
Closing a channel is an operation taken by the sender to tell the receiver that there is no more data coming on the channel. Clearly sending a value on a channel that has been closed is an error. By analogy, closing a channel that has been closed--trying to send an additional piece of information on that channel, namely that there is no more data coming--is an error. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.