Comment by danenania
I like WaitGroup as a concept, but I often end up using a channel instead for clearer error handling. Something like:
errCh := make(chan error)
for _, url := range urls {
go func(url string){
errCh <- http.Get(url)
}(url)
}
for range urls {
err := <-errCh
if err != nil {
// handle error
}
}
Should I be using WaitGroup instead? If I do, don't I still need an error channel anyway—in which case it feels redundant? Or am I thinking about this wrong? I rarely encounter concurrency situations that the above pattern doesn't seem sufficient for.
You would probably benefit from errgroup, https://pkg.go.dev/golang.org/x/sync/errgroup
But channels already do the waiting part for you.