Skip to content

Instantly share code, notes, and snippets.

@bobbywilson0
Created February 24, 2013 18:01
Show Gist options
  • Save bobbywilson0/5024845 to your computer and use it in GitHub Desktop.
Save bobbywilson0/5024845 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func sum(nums chan int) {
acc := 0
for x := range nums {
acc += x
fmt.Println(acc)
}
}
func main() {
nums := make(chan int)
go func(nums chan int) {
for i, j := 0, 1; i < 4000000; i, j = j, j + i {
if i % 2 == 0 {
nums <- i
}
}
}(nums)
go sum(nums)
// sleep so it doesn't return before any works done, don't know a way around this
time.Sleep(0.001 * 1e9)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment