I'm sure others will supply their opinions. :-)
(/cc all)
Why is close() allowed on receive-only chans?
Sent from my iPhone, so pardon any spelling or punctuation issues!
Dan
But closing a channel in the receiving end is, unfortunately, allowed.
When closed was removed, I proposed to remove close too and merge it
with the send operation:
http://groups.google.com/group/golang-nuts/browse_thread/thread/d91865ae306a081b/
(which neither disallow it unless you have a receive only channel, but
makes it more awkward).
This idea was rejected, and it is not my intention to start that
discussion again, but I'm bringing it here because I find thinking
about it that way a useful rule of thumb of when I should not be
closing a channel and maybe others will benefit of this point of view
too.
--
- yiyus || JGL .
Thanks. Though it's more a way of managing goroutines than managing
channels. It gives a very convenient way of terminating multiple
goroutines - the alternative that I have used of sending on a term
channel requires that the terminating goroutines resend the term signal.
One of the cases that is still complicated (relatively, not absolutely)
is the case of a generator. When you create a goroutine/channel form of
a generator closing the channel terminates the generator through a
panic. I guess to do this now I should have the generator-creating
function return a value channel *and* a stop channel rather than just a
value channel?
thanks
Dan
Have I misunderstood what you said? There seems to be no way to get
the loop to end unless close is called.