diff --git a/concurrency/range-close/go.go b/concurrency/range-close/go.go new file mode 100644 index 0000000..5241e23 --- /dev/null +++ b/concurrency/range-close/go.go @@ -0,0 +1,22 @@ +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) + } +}