Documentation ¶
Overview ¶
Package taskgroup provides a mix of multierr and errgroup See documentation for https://pkg.go.dev/go.uber.org/multierr and https://pkg.go.dev/golang.org/x/sync/errgroup
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group interface { Ctx() context.Context Wait() error Go(name string, f func(logger *zap.Logger) error) }
Group manages goroutines and collect all the errors. See https://pkg.go.dev/golang.org/x/sync/errgroup#group for more information
Example ¶
package main import ( "errors" "fmt" "go.uber.org/multierr" "go.uber.org/zap" "github.com/neondatabase/autoscaling/pkg/util/taskgroup" ) func main() { g := taskgroup.NewGroup(zap.NewNop()) g.Go("task1", func(_ *zap.Logger) error { return errors.New("error 1") }) g.Go("task2", func(_ *zap.Logger) error { return errors.New("error 2") }) err := g.Wait() // Using golang.org/x/sync/errgroup would return a return error depending on which goroutine was scheduled first errs := multierr.Errors(err) fmt.Println("Got", len(errs), "errors") }
Output: Got 2 errors
type GroupOption ¶
type GroupOption func(*group)
func WithPanicHandler ¶
func WithPanicHandler(f func(any)) GroupOption
WithPanicHandler sets a panic handler for the group.
func WithParentContext ¶
func WithParentContext(ctx context.Context) GroupOption
WithParentContext sets the parent context for the group.
Click to show internal directories.
Click to hide internal directories.