group

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: MIT Imports: 3 Imported by: 3

README

Group

A group provides a way manage the lifetime of a group of related goroutines.

Documentation

Overview

package group provides a way to manage the lifecycle of a group of goroutines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type G

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

G manages the lifetime of a set of goroutines from a common context. The first goroutine in the group to return will cause the context to be canceled, terminating the remaining goroutines.

func New

func New(opts ...Option) *G

New creates a new group.

func (*G) Add

func (g *G) Add(fn func(context.Context) error)

add adds a new goroutine to the group. The goroutine should exit when the context passed to it is canceled.

func (*G) Wait

func (g *G) Wait() error

wait waits for all goroutines in the group to exit. If any of the goroutines fail with an error, wait will return the first error. Wait waits for all goroutines in the group to exit. If any of the goroutines fail with an error, Wait will return the first error.

type Option added in v1.0.1

type Option func(*G)

func WithContext added in v1.0.1

func WithContext(ctx context.Context) Option

WithContext uses the provided context for the group.

Jump to

Keyboard shortcuts

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