Documentation ¶
Overview ¶
Package task provides an alternative to errgroup package with builtin context cancellation support.
This packages uses go.uber.org/multierr to combine errors from failed tasks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CancelCondition ¶ added in v0.0.3
CancelCondition is a condition for canceling the task group.
func CancelOnError ¶ added in v0.0.3
func CancelOnError() CancelCondition
CancelOnError indicates that task group should return on non-nil error. This is the same behavior as the golang.org/x/sync/errgroup package.
func CancelOnReturn ¶ added in v0.0.3
func CancelOnReturn() CancelCondition
CancelOnReturn indicates that task group should be canceled if any subtask returns.
func NeverCancel ¶ added in v0.0.3
func NeverCancel() CancelCondition
NeverCancel indicates that task group should not be canceled until all subtasks complete.
type Executor ¶ added in v0.0.3
type Executor interface {
Execute(ctx context.Context, cond CancelCondition, tasks ...Task) error
}
Executor abstracts the execution order for task groups.
func ParallelExecutor ¶ added in v0.0.3
func ParallelExecutor() Executor
ParallelExecutor returns an Executor instance for parallel execution.
func SequentialExecutor ¶ added in v0.0.3
func SequentialExecutor() Executor
SequentialExecutor returns an Executor instance for sequential execution.
type Task ¶
Task is a function that performs some work in foreground.
func Contextify ¶
Contextify adds context cancellation support to the task using the given shutdown function.
func Parallel ¶ added in v0.0.3
func Parallel(cond CancelCondition, tasks ...Task) Task
Parallel returns a function that executes a group of tasks in parallel using the given cancellation condition. The resulting Task returns combined errors for all failed subtasks.
func Sequential ¶ added in v0.0.3
func Sequential(cond CancelCondition, tasks ...Task) Task
Sequential returns a function that executes a group of tasks sequentially using the given cancellation condition. The resulting Task returns combined errors for all failed subtasks.