Created
July 5, 2019 06:35
-
-
Save xin053/7609ed7bcd4c556b2ffc8bd4ae2a2b19 to your computer and use it in GitHub Desktop.
[go select] go select #go #select
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select { | |
case <-ch1: | |
//... | |
case x:= <-ch2: | |
//... | |
case ch3 <- y: | |
//... | |
default: | |
//... | |
} | |
// select 会等待 case 中能够执行的 case 去执行,当有多个 case 同时就绪时, select 会随机选择一个执行 | |
// 对一个 nil 的 channel 发送和接收会永远阻塞,在 select 语句中操作 nil 的 channel 永远都不会被 select 到 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment