One minute
Handling multiple errors in goroutines
A lot of times while developing Go application we have to deal with slower tasks wich we prefer to run it in parallel spinning up new goroutines. This adds some complexity when you have to handle errors of these goroutines. Latelly I’ve learned about (Multierror by Hashicorp)[github.com/hashicorp/go-multierror] which give a very easy way to handle is.
Let’s see an example:
var g multierror.Group
g.Go(func() error {
// your code
})
g.Go(func() error {
// your code
})
g.Go(func() error {
// your code
})
err := g.Wait().ErrorOrNil()
if err != nil {
// handle error
}