-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Milestone
Description
I propose extending the x/errgroup API with a few convenience functions,
- Context() context.Context - return the error group cancelable context,
- GoContext(func(context.Context) error) - pass the produced ctx on to functions,
This requires:
- Add the produced context.Context value to Group{},
- Have the ability to read it afterwards with Context(),
- Pass context to functions with GoContext(func(context.Context) error) convenience
The convenience function can be easily implemented as a wrapper:
func (g *Group) GoContext(fn func(context.Context) error) {
g.Go(func() error {
return fn(g.Context())
}
}
The suggested naming is in line with http.Request
Context(), and database/sql
function signatures like ExecContext(...). The impact on code readability on codebases should be positive, as the wrapping for context-aware functions is eliminated on the consumer implementation side. There are no backwards compatibility issues that I can see.
Are PRs for this area accepted, any concerns? I'm more than willing to submit a PR for extending the functionality of this package.
davecheney, as and justinruggles