1
0
gotour-notes/concurrency/range-close/go.go

23 lines
276 B
Go
Raw Normal View History

package main
import (
"fmt"
)
func fibonacci(n int, c chan uint64) {
var x, y uint64 = 0, 1
for i := 0; i < n; i++ {
c <- x
x, y = y, x+y
}
close(c)
}
func main() {
fc := make(chan uint64, 80)
go fibonacci(cap(fc), fc)
for i := range fc {
fmt.Println(i)
}
}