Created
February 24, 2013 18:01
-
-
Save bobbywilson0/5024845 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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