limitgroup

package module
v0.0.0-...-2bfe6a8 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: MIT Imports: 4 Imported by: 0

README

go-limitgroup

Documentation

Overview

Package limitgroup provides synchronization, error propagation, and resource management for groups of goroutines working on common subtasks that are part of the same overall task.

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
}

Group works exactly like a golang.org/x/sync/errgroup.Group, but limits the maximum number of in-flight subtasks.

A zero Group is invalid. Use WithContext to construct a new Group.

func WithContext

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

WithContext returns a new Group and an associated Context derived from ctx.

If the given limit is less than or equal to zero, a default of two times the number of CPUs is used.

func (*Group) Go

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

Go calls the given function in a new goroutine after a semphore is acquired. If there is an error acquiring the semaphore, the error cancels the Group and is returned.

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

func (Group) Limit

func (lg Group) Limit() int64

Limit returns the maximum level of concurrency for the Group.

func (*Group) Wait

func (lg *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.

Jump to

Keyboard shortcuts

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