Help us shape the future of Go! Take the 2026 Go Developer Survey

errgroup

package
v0.23.2 Latest Latest
Warning

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

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

Documentation

Overview

Package errgroup runs a group of functions in goroutines, collects the first error, and cancels the group's context when one fails. It is the subset of golang.org/x/sync/errgroup the agent loop uses (WithContext, SetLimit, Go, Wait), with the same semantics, written against the standard library so the core module requires nothing outside it.

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 set of goroutines working on one task. Create it with WithContext.

func WithContext

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

WithContext returns a new Group and a context derived from ctx. The context is cancelled, with the error as its cause, the first time a function passed to Go returns a non-nil error, and otherwise when Wait returns.

func (*Group) Go

func (g *Group) Go(f func() error)

Go runs f in a new goroutine, first blocking while the group is at its limit. The first non-nil error any f returns is Wait's result and cancels the group's context.

func (*Group) SetLimit

func (g *Group) SetLimit(n int)

SetLimit limits the number of functions running at once to n; a negative n removes the limit. It panics if functions are running under a limit, as x/sync/errgroup's does: they would release their slots into the new semaphore and block. Call it before the first Go.

func (*Group) Wait

func (g *Group) Wait() error

Wait blocks until every function passed to Go has returned, cancels the group's context, and returns the first non-nil error, if any.

Jump to

Keyboard shortcuts

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