Documentation ¶
Overview ¶
Package errgroupx implements a modified version of errgroup's Group, keeping the derived context internally and passing to functions called via Go.
Storing a context in a struct is technically an antipattern, but using errgroup in practice can introduce unwanted context variables into the scope where the group is used.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrStop = errors.New("errgroupx: stop")
ErrStop is a sentinel error used when stopping a group.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group wraps errgroup's Group, keeping the derived context to pass to functions called via Go.
func FromContext ¶
FromContext returns a new Group 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 ¶
Go calls the given function in a new goroutine.
The first call to return a non-nil error cancels the group; its error will be returned by Wait.
func (*Group) Stop ¶
func (g *Group) Stop()
Stop stops the group by running a function on it that returns ErrStop.
func (*Group) Wait ¶
Wait blocks until all function calls from the Go method have returned, then returns the first non-nil error (if any) from them.
func (*Group) WaitIgnoreStop ¶
WaitIgnoreStop works like Wait, but will return nil if the error is ErrStop.