main.go 代码如下:
package main
import "fmt"
func feobonaqi(c, quit chan int) {
x, y := 1, 1
for {
select {
case c <- x:
x = y
y = x + y
case <-quit:
fmt.Println("listen quit")
return
}
}
}
func main() {
c := make(chan int)
quit := make(chan int)
go func() {
for i := 0; i < 20; i++ {
fmt.Println(<-c)
}
quit <- 0
}()
feobonaqi(c, quit)
fmt.Println("main process exit")
}
有疑问加站长微信联系(非本文作者)