This is a created article in which the information may have evolved or changed.
Look at the code first:
package mainimport ( "fmt" "runtime")func main() { runtime.GOMAXPROCS(1) int_chan := make(chan int, 1) string_chan := make(chan string, 1) int_chan <- 1 string_chan <- "hello" select { case value := <-int_chan: fmt.Println(value) case value := <-string_chan: panic(value) } fmt.Println(123)}
Run two times and the results are:
E:\go_study>go run 4.go1123E:\go_study>go run 4.go1123E:\go_study>go run 4.go1123E:\go_study>go run 4.go1123E:\go_study>go run 4.gopanic: hellogoroutine 1 [running]:main.main() E:/go_study/4.go:18 +0x2f4exit status 2E:\go_study>
Found no, if two cases are satisfied with the condition, it is pseudo-random select one to execute, rather than the previous thought of the top-to-bottom to determine which case can be executed.
Also, when a case is executed, it exits select because it prints 123.
Finally, if no case can be executed, execute default immediately, then exit Select.
Reference