Skip to content

Instantly share code, notes, and snippets.

@souvikhaldar
Created January 31, 2019 16:49
Show Gist options
  • Save souvikhaldar/745719bd21a0b2e610d900c08a51a97d to your computer and use it in GitHub Desktop.
Save souvikhaldar/745719bd21a0b2e610d900c08a51a97d to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func fibonacci(n int, c chan int) {
x, y := 0, 1
for i := 0; i < n; i++ {
time.Sleep(3 * time.Second)
c <- x
x, y = y, x+y
}
close(c)
}
func main() {
c := make(chan int, 10)
go fibonacci(cap(c), c)
for i := range c {
fmt.Println(i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment