This is indeed what Go is great for. But your code example is a bit wonky :) Specifically,
for {
select {
case r := <-ch:
// do something with r
default:
fmt.Printf(".")
time.Sleep(5e7)
}
}
You're needlessly blocking 50ms on every iteration. (Side note: time.Sleep(50 * time.Millisecond) better captures your intent.) Better to reformulate that as for {
select {
case r := <-ch:
// do something with r
case <-time.After(50*time.Millisecond):
fmt.Printf(".")
}
}
Or, if you don't need the dots in the output, for i := 0; i < cap(ch); i++ {
r := <-ch
// do something with r
}