Created
February 20, 2018 15:17
-
-
Save Aracki/d7dc935c7b2535a94c471c5b5a2aa961 to your computer and use it in GitHub Desktop.
Concurrent program go - 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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