Skip to content

Instantly share code, notes, and snippets.

@xin053
Created July 5, 2019 06:35
Show Gist options
  • Save xin053/7609ed7bcd4c556b2ffc8bd4ae2a2b19 to your computer and use it in GitHub Desktop.
Save xin053/7609ed7bcd4c556b2ffc8bd4ae2a2b19 to your computer and use it in GitHub Desktop.
[go select] go select #go #select
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