//producer func testSelect(c,quit chan int){ x, y :=0,1 for{ select { case c<-x: x,y = y,x+y case <-quit: fmt.Print("quit...") return } } } func main() { c := make(chan int) quit := make(chan int) go func(){//consumer for i:=0;i<20;i++{ fmt.Print(" ",<-c) } quit <- 1 }() testSelect(c,quit)//consumer }
Go routine 实现斐波那契
最新推荐文章于 2023-06-23 15:48:55 发布