I'm not sure what I am missing, but I have a dead end error. I use the buffer channel, which I use after completing all the procedures. The channel has a capacity of 4, and I start 4 procedures, so I expect it to be "closed" automatically as soon as it reaches its maximum capacity.
package main
import "fmt"
import "sync"
func main() {
ch := make(chan []int, 4)
var m []int
var wg sync.WaitGroup
for i := 0; i < 5; i++ {
wg.Add(1)
go func() {
defer wg.Done()
ch <- m
return
}()
}
wg.Wait()
for c := range ch {
fmt.Printf("c is %v", c)
}
}
source
share