errgroup

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package errgroup is bit more advanced than golang.org/x/sync/errgroup. Major difference is that when error group is created with WithContext the parent context would implicitly cancel all functions called by Go method.

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
}

The Group is superior errgroup.Group which aborts whole group execution when parent context is cancelled

func WithContext

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

WithContext creates Group and store inside parent context so the Go method would respect parent context cancellation

func (*Group) Go

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

Go runs the provided f function in a dedicated goroutine and waits for its completion or for the parent context cancellation.

func (*Group) SetLimit

func (g *Group) SetLimit(n int)

SetLimit limits the number of active goroutines in this group to at most n. A negative value indicates no limit.

Any subsequent call to the Go method will block until it can add an active goroutine without exceeding the configured limit.

The limit must not be modified while any goroutines in the group are active.

func (*Group) TryGo

func (g *Group) TryGo(f func() error) bool

TryGo calls the given function in a new goroutine only if the number of active goroutines in the group is currently below the configured limit.

The return value reports whether the goroutine was started.

func (*Group) Wait

func (g *Group) Wait() error

Wait blocks until all function calls from the Go method have returned, then returns the first non-nil error (if any) from them. If the error group was created via WithContext then the Wait returns error of cancelled parent context prior any functions calls complete.

Jump to

Keyboard shortcuts

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