I'm wondering how can I drain / close the buffered channels so that I don't get into the deadlock? I'm using range to loop through the channels but it seems that although they are "read" they don't get closed like the non-buffered channels do.
package main
func main() {
cp := 2
ch := make(chan string, cp)
for i := 0; i < cp; i++ {
go send(ch)
}
go send(ch)
for lc := range ch {
print(lc)
}
}
func send(ch chan string) {
ch <- "hello
"
}