course/Concurrency/select.go

16 lines
318 B
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main
import "fmt"
func main() {
//第一次1select选择一个能执行的即 ch<-i,把1放入通道第二次不能放入取出第三次再放入第四次再取出
ch := make(chan int, 1)
for i := 1; i <= 10; i++ {
select {
case x := <-ch:
fmt.Println(x)
case ch <- i:
}
}
}