I am new to Golang, I read from the official spec of select that I will do a monotonous pseudo-random when more messages can go on, but when I tried the following code
package main
import (
"fmt"
)
func main() {
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 prints "two received", it seems, not a random result, so where am I mistaken?
The code can be a test here .
source
share