group

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: MIT Imports: 2 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
}

A 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(ctx context.Context) *G

New returns a new group using the given context.

func (*G) Add

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

Add runs fn in a new goroutine and adds it 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.

Jump to

Keyboard shortcuts

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