Hacker News new | ask | show | jobs
by benhoyt 1100 days ago
It looks like sync/errgroup is a proposal, but not in the standard library (not yet, at any rate): https://github.com/golang/go/issues/57534
1 comments

Oh that's right. I imported it via golang.org/x/sync/errgroup
Even the author of errgroup does not want errgroup to enter the stdlib for the reasons he mentions:

There are two significant problems with the API:

An errgroup.WithContext today cancels the Context when its Wait method returns, which makes it easier to avoid leaking resources but somewhat prone to bugs involving accidental reuse of the Context after the call to Wait.

The need to call Wait in order to free resources makes errgroup.WithContext unfortunately still somewhat prone to leaks. If you start a bunch of goroutines and then encounter an error while setting up another one, it's easy to accidentally leak all of the goroutines started so far — along with their associated Context — by writing