add english version

This commit is contained in:
astaxie
2014-05-10 18:05:31 +08:00
parent 946300f0b1
commit eb5220f7eb
269 changed files with 16101 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
// Example code for Chapter 2.7 from "Build Web Application with Golang"
// Purpose: Shows how to create and use a unbuffered channel
package main
import "fmt"
func sum(a []int, c chan int) {
total := 0
for _, v := range a {
total += v
}
c <- total // send total to c
}
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, y := <-c, <-c // receive from c
fmt.Println(x, y, x+y)
}