errgroup

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	// FailFast causes the Group to cancel all goroutines immediately
	// when one goroutine returns an error.
	// FailFast must be set before any [Runner] is started.
	FailFast bool
	// contains filtered or unexported fields
}

Group allows running a number of Runner concurrently and aggregating their errors.

Using the default value of a Group is a valid use.

Its interface is inspired by the stdlib experiement errgroup: https://pkg.go.dev/golang.org/x/sync@v0.19.0/errgroup

func WithContext

func WithContext(ctx context.Context) *Group

WithContext returns a new Group.

A group instantiated this way should only live for the lifetime of the calling function as this stores the context, which can cause unintended side effects.

func (*Group) Go

func (g *Group) Go(runner Runner)

Go starts a Runner in a goroutine bound by the context.Context the Group was initialized with.

func (*Group) Wait

func (g *Group) Wait() error

Wait waits until all Runner started with Group.Go have finished and returns an aggregate of their errors.

type Runner

type Runner func(context.Context) error

Runner is a function that can be executed by a [Grouo].

Jump to

Keyboard shortcuts

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