Documentation
¶
Overview ¶
Package errgroup provides error synchronization and combination tools.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All executes all of the given functions in parallel, and collects and combines all of their returned errors.
func AllInline ¶
AllInline executes all of the given functions serially in the calling goroutine, and collects and combines all of their returned errors.
func First ¶
First executes all of the given functions in parallel, and returns the first error returned by them.
func FirstInline ¶
FirstInline executes all of the given functions serially in the calling goroutine, and returns the first error returned by them.
Types ¶
type ContextErrFunc ¶
A ContextErrFunc is a function that accepts a context.Context and returns an error.
type ErrFunc ¶
type ErrFunc = func() error
An ErrFunc is a function that returns an error.
func WithoutContext ¶
func WithoutContext(fn ContextErrFunc) ErrFunc
WithoutContext wraps a ContextErrFunc in an ErrFunc, providing a background context to the given ContextErrFunc.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is functionally similar to the standard library's x/sync/errgroup package, but offers more options to customize its behavior based on a given workflow. See the Options documentation for more information.
Groups cannot be reused. A zero-value Group is valid and ready to use.
func (*Group) Add ¶
Add executes the provided functions and stores returned errors for retrieval with Wait(). If the Group was configured using the WithInline() option, the given functions are executed immediately and serially in the calling goroutine; otherwise, the given functions are executed in parallel.
func (*Group) Wait ¶
Wait blocks until all functions passed to Add have been executed and returns an error if any were encountered.
The error return depends upon whether the Group was configured using the WithFirstOnly() option. If WithFirstOnly was not used, the returned error is an error containing a chain of all non-nil errors returned by the executed functions; if WithFirstOnly was used, the returned error is the first non-nil error returned verbatim by the first function to finish executing.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
An Option configures a Group.
func WithFirstOnly ¶
func WithFirstOnly() Option
WithFirstOnly returns an Option that configures a Group to return the first encountered error verbatim. Subsequently returned errors will be ignored.
func WithIgnoredErrors ¶
WithIgnoredErrors returns an Option that configures a Group to ignore errors that contain any of the given errors in their error chains.
func WithInline ¶
func WithInline() Option
WithInline returns an Option that configures a Group to execute all functions provided to Group.Add inline and serially within the calling goroutine. Note that this will make Group.Add a blocking call.
type Options ¶
type Options struct { // FirstOnly controls whether only the first non-nil error encountered will // be returned, or if all errors will be appended in a chain and returned. FirstOnly bool // IgnoredErrors is used to filter out unhelpful or immaterial errors, // such as io.EOF. IgnoredErrors []error // Inline controls whether functions passed to Group.Add are handled // inline and serially in the calling goroutine, or if they will be // executed in parallel in a background goroutine. Note that if Inline // is true, Group.Add becomes a blocking call. Inline bool }
Options are used to configure a Group.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns a new Options with sane defaults. Using default Options verbatim is functionally equivalent to using a zero-value Group.