Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrGroup ¶
type ErrGroup interface {
// Go calls the given function in a goroutine.
//
// The first call to return a non-nil error cancels the group; its error will be
// returned by Wait.
Go(fn func(ctx context.Context) error)
// Wait blocks until all function calls from the Go method have returned, then
// returns the first non-nil error (if any) from them.
Wait() error
}
A ErrGroup is a collection of goroutines working on subtasks that are part of the same overall task. A ErrGroup should not be reused for different tasks.
A zero Group is valid, has no limit on the number of active goroutines, and does not cancel on error. use WithContext instead.
func WithContext ¶
WithContext returns a new ErrGroup that is associated with a derived Context.
The returned group's Context is canceled in the following cases:
- The first time a goroutine started with Go returns a non-nil error.
- Or when Wait is called and returns.
If limit > 0, the group restricts the number of active goroutines to at most 'limit'. Additional functions passed to Go will be queued and executed only when running goroutines complete.
The derived Context is created with context.WithCancelCause, so the cancellation reason is preserved and can be retrieved via context.Cause.