errgroupx

package
v0.0.0-...-fb49ba0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package errgroupx implements a modified version of errgroup's Group, keeping the derived context internally and passing to functions called via Go.

Storing a context in a struct is technically an antipattern, but using errgroup in practice can introduce unwanted context variables into the scope where the group is used.

Index

Constants

This section is empty.

Variables

View Source
var ErrStop = errors.New("errgroupx: stop")

ErrStop is a sentinel error used when stopping a group.

Functions

This section is empty.

Types

type Group

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

Group wraps errgroup's Group, keeping the derived context to pass to functions called via Go.

func FromContext

func FromContext(ctx context.Context, opts ...Option) *Group

FromContext returns a new Group derived from ctx.

The derived Context is canceled the first time a function passed to Go returns a non-nil error or the first time Wait returns, whichever occurs first.

func (*Group) Go

func (g *Group) Go(f func(context.Context) error)

Go calls the given function in a new goroutine.

The first call to return a non-nil error cancels the group; its error will be returned by Wait.

func (*Group) Stop

func (g *Group) Stop()

Stop stops the group by running a function on it that returns ErrStop.

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.

func (*Group) WaitIgnoreStop

func (g *Group) WaitIgnoreStop() error

WaitIgnoreStop works like Wait, but will return nil if the error is ErrStop.

type Option

type Option func(*Group)

Option configures a Group.

func WithTrace

func WithTrace() Option

WithTrace enables OpenCensus tracing propagation from the main context to function with Go.

Jump to

Keyboard shortcuts

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