News for hackers. Stuff that matters.
Re:Go channels are bad by jerf on Wednesday March 02, 2016 @12:19PM (#11211330)
"When you have a pair of channels going in opposite directions between two goroutines, and either end can potentially initiate shutdown, it gets messy."

It does get messy to do it correctly, but I've found in the end it comes out less messy to have a channel communicating back to the sender that can be closed if you want the recipient to be able to close channel. I haven't needed it very often, but it happens. It still ends up simpler than hacking around the problem by trying to "close" the channel from the wrong end and the resulting panic handling.

For concreteness, at least from what I've experienced, the "messiness" is that if you close one of these channels, you may have to "drain" the other channel lest you let the other side block. If the other side is only using the channel in a "select" block with other options you may not need to but if it ever does a "bare" send you need to wait for the other end to send its close. This can be particularly complicated if for some reason the "draining" process has to do something other than drop the messages on the floor.

There are no comments on this comment yet.