taskgroup

package
v1.17.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorGroup

type ErrorGroup interface {
	Errors() []error
	Error() string
}

ErrorGroup is an error that contains a list of errors. This interface is implemented by `multierr.multiError`

type Filter

type Filter func(error) error

Filter is a function that takes an error and returns it (or a modified error) if it should be retained by `TaskGroup.Wait`.

type Task

type Task func() error

Task is a function that returns an error. See `taskgroup.New`.

type TaskGroup

type TaskGroup struct {
	// contains filtered or unexported fields
}

TaskGroup is a helper to make it easy to execute one or more `Task` functions and collect their errors, if any.

func New

func New() *TaskGroup

New returns a new TaskGroup, which can be used to execute one or more `Task` functions and collect their errors, if any.

func NewWithFilter

func NewWithFilter(f Filter) *TaskGroup

NewWithFilter returns a new TaskGroup, like `New`, but with a filter for optionally ignoring/muting errors using a `Filter` function.

func (*TaskGroup) Go

func (tg *TaskGroup) Go(t Task)

Go starts a `Task` in a background goroutine.

func (*TaskGroup) Wait

func (tg *TaskGroup) Wait() error

Wait blocks until all tasks are complete and returns a MultiError of their errors, if any. If the TaskGroup was created with a Filter, the filter will be called for each non-nil Task error, and only the non-nil error results will be returned. If multiple tasks errored (and more than one was not filtered), an `ErrorGroup` will be returned. Otherwise, returns the only error, or nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL