1
0

example of using range/close/for with channels

This commit is contained in:
Stephen M. McQuay 2012-09-03 08:38:02 -06:00
parent 3b54caef82
commit a8b0538b1b

View File

@ -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)
}
}