Skip to content

Instantly share code, notes, and snippets.

@haridutt12
Created November 21, 2018 09:21
Show Gist options
  • Save haridutt12/8eb019793b13bd3048e22eef36c44eb7 to your computer and use it in GitHub Desktop.
Save haridutt12/8eb019793b13bd3048e22eef36c44eb7 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func sum(a []int, ch chan int) {
s := 0
for i := 0; i < len(a); i++ {
s += a[i]
}
ch <- s
}
func main() {
a := []int{1, 2, -6, 5, 7, 8}
ch := make(chan int)
go sum(a[:len(a)/2], ch)
go sum(a[len(a)/2:], ch)
A, b := <-ch, <-ch
fmt.Println(A, b, A+b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment