When reading multiple values from a channel, using range
is a common pattern:
https://codeeval.dev/gist/4787e53410ebd82b3f4856eb274eaafe
Using a for range
loop is one of three ways to read values from a channel.
The loop ends when the channel is closed.
This is a common pattern when using worker pool: * create a single channel for all workers * launch workers * workers use for v := range chan
to pick up jobs to process * after enquing all jobs, close the channel so that worker goroutines end when they process all jobs from a channel