Skip to content

Instantly share code, notes, and snippets.

@kkpoon
Created September 5, 2017 14:42
Show Gist options
  • Save kkpoon/96df7c0df32b46ed2a8a02bd935f37fb to your computer and use it in GitHub Desktop.
Save kkpoon/96df7c0df32b46ed2a8a02bd935f37fb to your computer and use it in GitHub Desktop.
multi-channel consumer
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