Skip to content

alexbagnolini/errgroupcheck

Repository files navigation

errgroupcheck

CI Go Report Card Coverage MIT License

errgroupcheck is a linter that checks that you are calling errgroup.Wait() when using errgroup.Group from the golang.org/x/sync/errgroup package.

Installation

go install github.com/alexbagnolini/errgroupcheck@latest

Why

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.

Examples

Good usage

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()
}

Bad usage

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
	})
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages