[go-nuts] What 'select' is doing here?

2016-09-06 Thread Dave Cheney
Here's the same program rewritten.

https://play.golang.org/p/ANHNUcPjR2

If ch is writable, then select pseudo randomly chooses the first or second 
case. The default case is never taken unless ch is blocked, in which case the 
goroutine will block sending to ch indefinitely. 

-- 
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.


[go-nuts] What 'select' is doing here?

2016-09-06 Thread Pablo Rozas Larraondo
I'm trying to understand how the 'select' statement works internally. The
execution process of select as described in
https://golang.org/ref/spec#Select_statements says on number 2: "If one or
more of the communications can proceed, a single one that can proceed is
chosen via a uniform pseudo-random selection."

However, in this example: https://play.golang.org/p/1GKsbhES8s

I've defined two cases each calling a different function: A() and B(). When
I execute this code it seems to evaluate both functions (it waits till the
longest sleep in A and B finishes but returns a random 1 or 2).

Does this means that select choses a random case (as stated in the docs)
but evaluates both cases? Does anyone know what kind of concurrency
'select' uses internally to evaluate both functions?

Thanks for your help,
Pablo

Note: The Go Playground doesn't seem to return random responses as the ones
I see when I run the same code on my local computer. It might be related to
internal caching effects.

-- 
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.