channl与select

package main

import (
"fmt"
 
)
func fibol(c,quit chan int){

x,y := 1,1
 
for{
select{
 
case c <- x:
x = y
y = x+y

case <- quit:
fmt.Println("quit")
return
}
}
}
func main() {
c := make(chan int)
quit := make(chan int)
//sub go
go func(){
for i := 0; i<6; i++ {
fmt.Println(<-c)
}
quit <- 0
}()
// main go
fibol(c,quit)

}
 

 

 

 
posted @ 2021-03-25 15:48  hubb  阅读(140)  评论(0编辑  收藏  举报