5 ms·
This is usually why I end up using https://godoc.org/golang.org/x/sync/errgroup https://godoc.org/golang.org/x/sync/errgroup instead of straight go statements,
by lclarkmichalek 8y ago
This is usually why I end up using https://godoc.org/golang.org/x/sync/errgroup https://godoc.org/golang.org/x/sync/errgroup instead of straight go statements, as it addresses some of the cancellation and error propogation issues. When I think of my use of naked go statements, it's usually for periodic tasks; having something similarly structured for them would be a clear win to me (though potentially the impact is less significant, as it's less painful to write a well formed periodic task using the go statement and context).
- shabbyrobe 8y agoThank you! I had no idea about this package! I rolled my own similar thing, but I'd much rather be using something semi-blessed. Looks like I have some refactoring to do, but that's not always a bad thing.
- arghwhat 8y agoAh, neat. It's relatively new—I've always rolled my own implementation whenever I needed it (it's super simple, which is why this library is 67 lines of implementation, half being comments), but why roll your own when it's part of the (experimental) standard library?
- sagichmal 8y agohttps://godoc.org/github.com/oklog/run https://godoc.org/github.com/oklog/run is a more-general and IMO more-elegant version of errgroup.
- erik_seaberg 8y agoBe advised that errgroup doesn't recover from panics to prevent them from killing the process.
- atombender 8y agoErrGroup is nice, but it was created before contexts existed, and doesn't have support for cancellation. I have a bounded worker pool executor that handles cancellation that I'm currently extracting from a private project; shout out if interested.
- lclarkmichalek 8y agoThe errgroup I linked has a single constructor `WithContext(ctx.Context) (*Group, context.Context)`. I think you might be thinking of the stdlib's sync.ErrGroup :)
- atombender 8y agoOops, I didn't realize that. Thanks. Mine implementation supports a bounded (max concurrency) mode, though!