guys i was wondering if it is better to to range over channel or use select, if I have only one case (my channel) and signal the end with close of the given channel ?
Given the examples:
1. https://play.golang.org/p/3ZFdbgHSKyN
go func() {
for v := range ch {
// do some stuff
}
}()
2. https://play.golang.org/p/iCCkDge8j72
go func() {
for {
select {
case v, ok := <-ch:
if !ok {
return
}
// do some stuff
}
}
}()
Which solution would be preferred and why ? Please consider the fact that goroutines as such might be spawned many times (many workers).