>> You're only supposed to close a channel from the producer side.
> Why?

First, an appeal to authority: http://golang.org/pkg/builtin/#close
Notice the type of the argument: chan<-
That's a write-only port. Go's type system allows automatic coercion from
read/write ports to constrained read or write only ports. However, you
can't coerce a constrained port back to an unconstrained one.

See also the discussion here:
https://groups.google.com/d/topic/golang-nuts/pZwdYRGxCIk/discussion

There are a few points discussed there, but in summary: It is a programming
error to write a message to a closed channel. "close" is not a resource
cleanup operation, it is a control signal. It "flows" in the same direction
as the messages sent on the channel itself. If the receiver were allowed to
close the channel, then the sender would have no way of avoiding a
closed/write race condition.

This brings up another issue: Currently writing to a closed channel is a
no-op, but it probably should throw an exception. Similarly, closing a
closed channel is a no-op, but also probably should throw an exception.
Both are things that a well behaved sender should never do, since they know
when they close, so they know not to keep putting stuff in there. Or, they
are warned of the impending close by some coordination process & the same
rules apply.

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to