llerrgroup

package module
v0.2.0 Latest Latest
Warning

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

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

README

llerrgroup

llerrgroup augments golang.org/x/sync/errgroup to add parallelism to the errgroup.

If an error occurs, the iteration will be short-circuited and the first error returned.

Sample usage:

    urls := []string{"http://www.google.com", "http://www.bing.com", "add more..."}
	eg := llerrgroup.New(3)  // 3 parallel goroutines
	for _, url := range urls {
		if eg.Stop() {
			continue  // short-circuit the loop if we got an error
		}

		url := url  // lock value in loop's scope. The `func() error` below is the required signature to `Go()`.
		eg.Go(func() error {
			_, err := http.Get(url)
			return err
		})
	}
	if err := eg.Wait(); err != nil {
		// eg.Wait() will block until everything is done, and return the first error.
		return err
	}

License

MIT licensed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

func New

func New(parallelOperations int) *Group

func (*Group) CallsCount

func (g *Group) CallsCount() int

func (*Group) Free added in v0.2.0

func (g *Group) Free()

func (*Group) Go

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

func (*Group) SetSize

func (g *Group) SetSize(parallelOperations int)

func (*Group) Stop

func (g *Group) Stop() bool

Stop blocks for a free queue position, and returns whether you should stop processing requests. In a for loop

Jump to

Keyboard shortcuts

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