I am a beginner of Golang, I read from the official spec of select that I will do uniform pseudo-random when more of communications can proceed, but when I tried the following code
package main
import (
"fmt"
)
func main() {
// For our example we'll select across two channels.
c1 := make(chan string)
c2 := make(chan string)
go func() {
for {
c1 <- "one"
}
}()
go func() {
for {
c2 <- "two"
}
}()
for i := 0; i < 100; i++ {
select {
case msg1 := <-c1:
fmt.Println("received", msg1)
case msg2 := <-c2:
fmt.Println("received", msg2)
}
}
}
It always print 'received two', seems not to be a random result, so where am I wrong?
The code can be test here.