Skip to content

Instantly share code, notes, and snippets.

@Aracki
Created February 20, 2018 15:17
Show Gist options
  • Save Aracki/d7dc935c7b2535a94c471c5b5a2aa961 to your computer and use it in GitHub Desktop.
Save Aracki/d7dc935c7b2535a94c471c5b5a2aa961 to your computer and use it in GitHub Desktop.
Concurrent program go - 1
func main() {
ch := make(chan int)
out := make(chan int)
go func(ch1 chan int, out chan int) {
res := 0
for v := range ch1 {
fmt.Println("Receive: ", v)
res += v
}
out <- res
}(ch, out)
ch <- 1
ch <- 2
ch <- 3
close(ch)
fmt.Println("Total:", <-out)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment