Skip to content

Instantly share code, notes, and snippets.

@kenKanata56
Created December 19, 2017 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenKanata56/940ab343f613d5d430ad59cb96b70dca to your computer and use it in GitHub Desktop.
Save kenKanata56/940ab343f613d5d430ad59cb96b70dca to your computer and use it in GitHub Desktop.
package main
import "fmt"
func sum(s []int,c chan int){
sum := 0
for _, v := range s{
sum += v
}
c <- sum
}
func main(){
s := []int{1,2,3,4,5,6,7,8,9,10}
c := make(chan int)
go sum(s[:len(s)/2],c)
go sum(s[len(s)/2:],c)
x,y := <- c,<-c
fmt.Println(x,y,x+y)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment