Skip to content

Instantly share code, notes, and snippets.

@souvikhaldar
Created January 31, 2019 16:52
Show Gist options
  • Save souvikhaldar/96b5bc938eeb3a65eab632310e574f7b to your computer and use it in GitHub Desktop.
Save souvikhaldar/96b5bc938eeb3a65eab632310e574f7b to your computer and use it in GitHub Desktop.
package main
import "fmt"
func fibonacci(c, quit chan int) {
x, y := 0, 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)
go func() {
for i := 0; i < 10; i++ {
fmt.Println(<-c)
}
quit <- 0
}()
fibonacci(c, quit)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment