errgroup

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: AGPL-3.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 {
	// contains filtered or unexported fields
}

A Group is a collection of goroutines working on subtasks that are part of the same overall task.

A zero Group can be used if errors should not be tracked.

func WithNErrs

func WithNErrs(nerrs int) *Group

WithNErrs returns a new Group with length of errs slice upto nerrs, upon Wait() errors are returned collected from all tasks.

func (*Group) Go

func (g *Group) Go(f func() error, index int)

Go calls the given function in a new goroutine.

The errors will be collected in errs slice and returned by Wait().

func (*Group) Wait

func (g *Group) Wait() []error

Wait blocks until all function calls from the Go method have returned, then returns the slice of errors from all function calls.

func (*Group) WaitErr

func (g *Group) WaitErr() error

WaitErr blocks until all function calls from the Go method have returned, then returns the first error returned.

func (*Group) WithCancelOnError

func (g *Group) WithCancelOnError(ctx context.Context) (context.Context, context.CancelFunc)

WithCancelOnError will return a context that is canceled as soon as an error occurs. The returned CancelFunc must always be called similar to context.WithCancel. If the supplied context is canceled any goroutines waiting for execution are also canceled.

func (*Group) WithConcurrency

func (g *Group) WithConcurrency(n int) *Group

WithConcurrency allows to limit the concurrency of the group. This must be called before starting any async processes. There is no order to which functions are allowed to run. If n <= 0 no concurrency limits are enforced. g is modified and returned as well.

Jump to

Keyboard shortcuts

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