Created
November 1, 2017 21:41
-
-
Save mlafeldt/a7ab0f167c034deed14988ba728cbc3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
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) | |
} | |
func fibonacci(c chan<- int, quit <-chan int) { | |
x, y := 0, 1 | |
for { | |
select { | |
case c <- x: | |
x, y = y, x+y | |
case <-quit: | |
return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment