Files
bootdotdev-fcc-learn-golang…/course/13-channels/exercises/6-range/complete.go
wagslane 9be3074de6 first
2023-05-01 15:25:27 -06:00

41 lines
545 B
Go

package main
import (
"fmt"
"time"
)
func concurrrentFib(n int) {
ch := make(chan int)
go fibonacci(n, ch)
for v := range ch {
fmt.Println(v)
}
}
// TEST SUITE - Don't touch below this line
func test(n int) {
fmt.Printf("Printing %v numbers...\n", n)
concurrrentFib(n)
fmt.Println("==============================")
}
func main() {
test(10)
test(5)
test(20)
test(13)
}
func fibonacci(n int, ch chan int) {
x, y := 0, 1
for i := 0; i < n; i++ {
ch <- x
x, y = y, x+y
time.Sleep(time.Millisecond * 10)
}
close(ch)
}