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.
// Go never blocks; if the concurrency limit is reached, the function is
// queued and executed as running goroutines complete.
//
// The first call to return a non-nil error cancels the group; its error will be
// returned by Wait.
//
// Go may be called concurrently, but all calls must happen before Wait
// returns. Calling Go after Wait has returned panics when limit > 0.
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 must not be called concurrently with external Go calls that may
// increase the task count from zero (the same constraint as sync.WaitGroup).
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.
Use WithContext to create a ErrGroup.
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.