Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Contexts are canceled with this error when executors are awaited. GroupDoneError = errGroupDone //nolint:errname )
Functions ¶
This section is empty.
Types ¶
type AllErrsExecutor ¶
type AllErrsExecutor interface {
// Go submits a task to the Executor, to be run at some point in the future.
//
// Panics if Wait() has already been called.
// May panic if any submitted task has already panicked.
Go(func(context.Context) error)
// Wait waits until all submitted tasks have completed, then returns a
// MultiError of any errors that were returned by submitted tasks (or nil).
//
// After waiting, panics if any submitted task panicked.
Wait() MultiError
}
Executor that collects every error from the operations.
func GatherErrs ¶
func GatherErrs(executor Executor) AllErrsExecutor
Returns an executor similar to parallel.ErrGroup, except instead of only returning the first error encountered it returns a MultiError of any & all errors encountered (or nil if none).
These executors are even best-effort safe against misuse: if the owner panics or otherwise forgets to call Wait(), the goroutines started by this executor should still be cleaned up.
type CollectingAllErrsExecutor ¶
type CollectingAllErrsExecutor[T any] interface { // Go submits a task to the Executor, to be run at some point in the future. // // Panics if Wait() has already been called. // May panic if any submitted task has already panicked. Go(func(context.Context) (T, error)) // Wait waits until all submitted tasks have completed, then returns a slice // of the returned values from non-erring tasks and a MultiError of any // errors returned (or nil). // // After waiting, panics if any submitted task panicked. Wait() ([]T, MultiError) }
Executor that collects the returned values and errors of the operations.
func CollectWithErrs ¶
func CollectWithErrs[T any](executor Executor) CollectingAllErrsExecutor[T]
Returns an executor that collects both values and a MultiError of any & all errors (or nil if none). Return values are not included in the results if that invocation returned an error. Execution does not stop if errors are encountered, only if there is a panic.
These executors are even best-effort safe against misuse: if the owner panics or otherwise forgets to call Wait(), the goroutines started by this executor should still be cleaned up.
type CollectingExecutor ¶
type CollectingExecutor[T any] interface { // Go submits a task to the Executor, to be run at some point in the future. // // Panics if Wait() has already been called. // May panic if any submitted task has already panicked. Go(func(context.Context) (T, error)) // Wait waits until all submitted tasks have completed, then returns a slice // of the returned values from non-erring tasks or an error if any occurred. // // After waiting, panics if any submitted task panicked. Wait() ([]T, error) }
Executor that collects all the return values of the operations, then returns the resulting slice or an error if any occurred.
func Collect ¶
func Collect[T any](executor Executor) CollectingExecutor[T]
Returns an executor that collects all the return values from the functions provided, returning them (in no guaranteed order!) in a slice at the end.
These executors are even best-effort safe against misuse: if the owner panics or otherwise forgets to call Wait(), the goroutines started by this executor should still be cleaned up.
type ErrGroupExecutor ¶
type ErrGroupExecutor interface {
// Go submits a task to the Executor, to be run at some point in the future.
//
// Panics if Wait() has already been called.
// May panic if any submitted task has already panicked.
Go(func(context.Context) error)
// Wait waits until all submitted tasks have completed, then returns one
// error if any errors were returned by submitted tasks (or nil).
//
// After waiting, panics if any submitted task panicked.
Wait() error
}
Executor that runs until the first error encountered
func ErrGroup ¶
func ErrGroup(executor Executor) ErrGroupExecutor
Returns an executor that halts if any submitted task returns an error, and returns one error from Wait() if any occurred.
type Executor ¶
type Executor interface {
// Go submits a task to the Executor, to be run at some point in the future.
//
// Panics if Wait() has already been called.
// May panic if any submitted task has already panicked.
Go(func(context.Context))
// Wait waits until all submitted tasks have completed.
//
// After waiting, panics if any submitted task panicked.
Wait()
// contains filtered or unexported methods
}
Executor that runs the given functions and can wait for all of them to finish.
func Limited ¶
Creates a parallelism-limited executor which starts up to a given number of goroutines, which each run the provided functions until done.
These executors are even best-effort safe against misuse: if the owner panics or otherwise forgets to call Wait(), the goroutines started by this executor should still be cleaned up.
func Unlimited ¶
Creates a basic executor which runs all the functions given in one goroutine each. Composes starting the goroutines, safe usage of WaitGroups, and as a bonus any panic that happens in one of the provided functions will be ferried over and re-panicked in the thread that owns the executor (that is, the code calling Wait() and Go()), so the whole process doesn't die.
type FeedingAllErrsExecutor ¶
type FeedingAllErrsExecutor[T any] interface { // Go submits a task to the Executor, to be run at some point in the future. // // Panics if Wait() has already been called. // May panic if any submitted task has already panicked. Go(func(context.Context) (T, error)) // Wait waits until all submitted tasks have completed and all returned // values from non-erring tasks have been processed by the receiver // function, then returns a MultiError of any errors that were returned by // the tasks (or nil). // // After waiting, panics if any submitted task panicked. Wait() MultiError }
Executor that feeds all the return values of the operations to a user function and collects returned errors.
func FeedWithErrs ¶
func FeedWithErrs[T any](executor Executor, receiver func(context.Context, T) error) FeedingAllErrsExecutor[T]
Returns an executor that collects all the return values from the functions provided, passing them all (in no guaranteed order!) to the provided receiver, which runs in a single goroutine by itself. Execution does not stop if errors are encountered from either the work functions or the receiver function; those errors are all combined into the MultiError returned by Wait().
These executors are even best-effort safe against misuse: if the owner panics or otherwise forgets to call Wait(), the goroutines started by this executor should still be cleaned up.
type FeedingExecutor ¶
type FeedingExecutor[T any] interface { // Go submits a task to the Executor, to be run at some point in the future. // // Panics if Wait() has already been called. // May panic if any submitted task has already panicked. Go(func(context.Context) (T, error)) // Wait waits until all running tasks have completed and all returned values // from non-erring tasks have been processed by the receiver function, then // returns an error if any occurred. // // After waiting, panics if any submitted task panicked. Wait() error }
Executor that feeds all the return values of the operations to a user function.
func Feed ¶
Returns an executor that collects all the return values from the functions provided, passing them all (in no guaranteed order!) to the provided receiver, which runs in a single goroutine by itself. In the event of an error from either the work functions or the receiver function, execution halts and the first error is returned.
These executors are even best-effort safe against misuse: if the owner panics or otherwise forgets to call Wait(), the goroutines started by this executor should still be cleaned up.
type MultiError ¶
MultiError is used internally to wrap multiple errors that occur within a function
func CombineErrors ¶
func CombineErrors(errs ...error) MultiError
Combine multiple errors into one MultiError, discarding all nil errors and flattening any existing MultiErrors. If the result has no errors, the result is nil.
func NewMultiError ¶
func NewMultiError(errs ...error) MultiError
type WorkerPanic ¶ added in v0.2.0
type WorkerPanic struct {
// Panic contains the originally panic()ed value.
Panic any
// Stacktraces contains the stacktraces of the panics. The stack trace of
// the line that threw the original Panic value appears first, and any other
// stack traces from other parallel groups that received this panic and re-
// threw it appear in order afterwards.
Stacktraces []string
}
WorkerPanic represents a panic value propagated from a task within a parallel executor, and is the main type of panic that you might expect to receive.
func (WorkerPanic) Error ¶ added in v0.2.2
func (wp WorkerPanic) Error() string
We pretty-print our wrapped panic type including the captured stack traces.