Documentation ¶
Overview ¶
Package errgroup is a minor refactor of golang.org/x/sync/errgroup to better enable context propagation and short-circuiting of managed goroutines.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
A Group is a collection of goroutines working on subtasks that are part of the same overall task.
func WithContext ¶
WithContext returns a new Group and an associated Context derived from ctx.
The derived Context is canceled the first time a function passed to Go returns a non-nil error or the first time Wait returns, whichever occurs first.
func (*Group) Go ¶
func (g *Group) Go(fn GroupableFunc)
Go calls the given function in a new goroutine. Critically, functions passed to Go must respect the provided Context and abort their execution if it is canceled.
The first call to return a non-nil error cancels the group; its error will be returned by Wait.
type GroupableFunc ¶
A GroupableFunc is a function that is able to be processed as part of a Group. Such functions must respect the live-ness of the provided Context.
type MultiGroup ¶
type MultiGroup struct {
// contains filtered or unexported fields
}
MultiGroup is a Group variant that accumulates errors rather than simply returning the first encountered. Semantically, this affords callers the ability to determine whether or not launched goroutines should abort immediately once the provided context is canceled. If callers choose not to respect the context, it is their responsibility to ensure that goroutines do not leak.
func MultiWithContext ¶
func MultiWithContext(ctx context.Context) (*MultiGroup, context.Context)
MultiWithContext returns a new MultiGroup and an associated Context derived from ctx.
The derived Context is canceled the first time a function passed to Go returns a non-nil error or the first time Wait returns, whichever occurs first.
func (*MultiGroup) Go ¶
func (g *MultiGroup) Go(fn GroupableFunc)
Go calls the given function in a new goroutine. Callers may choose whether or not to respect the context (in order to have multiple launched routines' errors combined), however it is the caller's responsibility to avoid goroutine leaks in such cases.
func (*MultiGroup) Wait ¶
func (g *MultiGroup) Wait() error
Wait blocks until all function calls from the Go method have returned, then returns all non-nil errors (if any) from them, combined via multierr.