Created
September 5, 2017 14:42
-
-
Save kkpoon/96df7c0df32b46ed2a8a02bd935f37fb to your computer and use it in GitHub Desktop.
multi-channel consumer
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
package main | |
import "fmt" | |
func sum(id int, c <-chan int) { | |
for num := range c { | |
fmt.Printf("%d %d\n", id, num) | |
} | |
} | |
func main() { | |
s := []int{11, 12, 13, 14, 15, 16, 17, 18, 19} | |
c := make(chan int) | |
for i := 0; i < 3; i++ { | |
go sum(i, c) | |
} | |
for _, i := range s { | |
c <- i | |
} | |
fmt.Scanln() | |
fmt.Println("done") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment