errgroup

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package errgroup coordinates goroutines that share a cancellation context.

The first goroutine error cancels the group context and is returned by Wait; recovered panics are converted into errors.

Index

Constants

This section is empty.

Variables

View Source
var ErrPanicRecovered = errors.New("errgroup: panic recovered")

ErrPanicRecovered is returned when a goroutine in the group panics.

Functions

This section is empty.

Types

type Group

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

Group manages a set of goroutines that share a cancellation context. The first error returned by any goroutine cancels the group's context and is returned by Wait. Subsequent errors are discarded.

func WithContext

func WithContext(ctx context.Context) (*Group, context.Context)

WithContext returns a new Group and a derived context.Context. The derived context is canceled when the first goroutine in the Group returns a non-nil error or when Wait returns, whichever occurs first.

func (*Group) Go

func (grp *Group) Go(fn func() error)

Go starts a new goroutine in the Group. The first non-nil error returned by a goroutine is recorded and triggers cancellation of the group context. Callers must not mutate shared state without synchronization.

func (*Group) SetLogger

func (grp *Group) SetLogger(logger libLog.Logger)

SetLogger sets an optional logger for panic recovery observability. When set, panics recovered in goroutines will be logged before the error is propagated via Wait.

func (*Group) Wait

func (grp *Group) Wait() error

Wait blocks until all goroutines in the Group have completed. It cancels the group context after all goroutines finish and returns the first non-nil error (if any) recorded by Go.

Jump to

Keyboard shortcuts

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