errgroupcheck is a linter that checks that you are calling errgroup.Wait()
when using errgroup.Group
from the golang.org/x/sync/errgroup
package.
go install github.com/alexbagnolini/errgroupcheck@latest
When using errgroup.Group
from the golang.org/x/sync/errgroup
package, it is important to call errgroup.Wait()
to ensure that all goroutines have finished before the main goroutine exits.
func errgroupWithWait() {
eg := errgroup.Group{}
eg.Go(func() error {
return nil
})
eg.Go(func() error {
return nil
})
// call to .Wait()
// (you probably want to check / return the error)
_ = eg.Wait()
}
func errgroupMissingWait() {
eg := errgroup.Group{} // golangci-lint will report "errgroup 'eg' does not have Wait called"
eg.Go(func() error {
return nil
})
eg.Go(func() error {
return nil
})
}