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