Right! Ok, I understand it now, there's no concurrent evaluation happening. And I understand what you meant when evaluating the functions before the select statement in your code.
Thank you very much for your help in understanding this Dave. Pablo On Wednesday, September 7, 2016 at 11:51:59 AM UTC+10, Dave Cheney wrote: > > The best description i've found comes from the spec, see the "execution of > select statement" section. > > https://golang.org/ref/spec#Select_statements > > The program I rewrote for you is identical to the one you wrote, all the > work to evaluate the RHS of the select cases happens "before" the select > statement, so if A() sleeps for 100ms, then B() sleeps for 1000ms, the > select statement is not executed until both operations have happened. > > > On Wednesday, 7 September 2016 11:48:02 UTC+10, Pablo Rozas-Larraondo > wrote: >> >> Thanks Dave. It seems though that whatever select chooses to run (A or B) >> the program takes 1000 ms to complete. I would expect the program to finish >> in 100 ms if A is chosen or 1000 ms in the case of B. I wonder if both >> functions are evaluated concurrently no matter which case select chooses. >> If this is true, does anyone know what kind of concurrency is the select >> statement using underneath? >> >> Cheers, >> Pablo >> >> On Wednesday, September 7, 2016 at 8:35:11 AM UTC+10, Dave Cheney wrote: >>> >>> 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.