Reading from the language spec:
For all the cases in the statement, the channel operands of receive
operations and the channel **and right-hand-side expressions of send
statements** are evaluated exactly once, in source order, upon entering the
"select" statement. The result is a set of channels to receive from or send
to, and the corresponding values to send.
I admit, the emphasized part caught me by surprise. Why? I would expect the
right-hand-side part of send statements to be evaluated *only* when the
case selected. This would allow someone to do something like:
case out <- q.Pop():
Now you have to mess with temporary variables and the code gets uglier.
I understand that it is how it is, but I'm wondering, is there any reason
it was chosen to be so?
/npat
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.