errgroup synchronizes goroutines while collecting function errors, avoiding the error channel required when combining sync.WaitGroup with concurrent work. section 7.2.4
Use an errgroup.Group to:
- Launch work with Go, passing functions that return errors. section 7.2.4
- Limit the number of goroutines running simultaneously with SetLimit(n). section 7.2.4
- Wait for the group and handle the returned error. section 7.2.4
Cooking rice and curry concurrently
var g errgroup.Group g.SetLimit(2) g.Go(func() error { cookRice(); return nil }) g.Go(cookCurry) if err := g.Wait(); err != nil { /* handle error */ }

