github.com/DARA-Project/GoDist-Scheduler@v0.0.0-20201030134746-668de4acea0d/examples/Select/simple_select.go (about) 1 package main 2 3 import "fmt" 4 5 func fibonacci(c, quit chan int) { 6 x, y := 0, 1 7 for { 8 select { 9 case c <- x: 10 x, y = y, x+y 11 case <-quit: 12 fmt.Println("quit") 13 return 14 } 15 } 16 } 17 18 func main() { 19 c := make(chan int) 20 quit := make(chan int) 21 go func() { 22 for i := 0; i < 10; i++ { 23 fmt.Println(<-c) 24 } 25 quit <- 0 26 }() 27 fibonacci(c, quit) 28 }