package main
import (
"runtime"
"sync"
)
func main() {
println("GOMAXPROCS", runtime.GOMAXPROCS(0))
n := 5
var wg sync.WaitGroup
wg.Add(n) := 5
ch := make(chan int, n)
for i := 0; i < n; i++ {
println("Processing ", i)
go process(i, ch)
wg.Add(1)
go consume(ch, &wg)
}
wg.Wait()
println("Finished the process")
}
func consume(ch chan int, wg *sync.WaitGroup) {
defer wg.Done()
println("Result ", <-ch)
}
func process(i int, ch chan int) {
ch <- (i * 5)
}
Playground: https://play.golang.org/p/pfZTmmVw0lUhttps://play.golang.org/p/3czBixAjxdT