Collapsing tree into more sane Go project layout

since I was in here looking at something unrelated...
This commit is contained in:
Dan Buch
2012-12-13 18:12:43 -05:00
parent 270eb1fc2d
commit 44999623da
19 changed files with 23 additions and 31 deletions

View File

@@ -0,0 +1,31 @@
package main
import (
"fmt"
"math"
"time"
)
func sum(a []int, c chan int) {
sum := 0
for _, v := range a {
sum += v
}
to_sleep := time.Duration(100*math.Abs(float64(sum))) * time.Millisecond
fmt.Printf("Sleeping %s...\n", to_sleep)
time.Sleep(to_sleep)
c <- sum
}
func main() {
a := []int{7, 2, 8, -9, 4, 0}
c := make(chan int)
go sum(a[:len(a)/2], c)
go sum(a[len(a)/2:], c)
x := <-c
fmt.Printf("x = %d\n", x)
y := <-c
fmt.Printf("y = %d\n", y)
fmt.Println(x, y, x+y)
}