errgroup

package module
Version: v0.0.0-...-779c8d7 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2016 License: BSD-3-Clause Imports: 2 Imported by: 38

README

Documentation

Overview

Package errgroup provides a Group that is capable of collecting errors as it waits for a collection of goroutines to finish.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMultiError

func NewMultiError(errs ...error) error

NewMultiError returns nil if all input errors passed in are nil. Otherwise, it coalesces all input errors into a single error instance. Useful for code like this:

func doThisAndThat() error {
  err1 := tryThis()
  err2 := tryThat()
  return errgroup.NewMultiError(err1, err2)
}

Types

type Group

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

Group is similar to a sync.WaitGroup, but allows for collecting errors. The collected errors are never reset, so unlike a sync.WaitGroup, this Group can only be used _once_. That is, you may only call Wait on it once.

func (*Group) Add

func (g *Group) Add(delta int)

Add adds delta, which may be negative. See sync.WaitGroup.Add documentation for details.

func (*Group) Done

func (g *Group) Done()

Done decrements the Group counter.

func (*Group) Error

func (g *Group) Error(e error)

Error adds an error to return in Wait. The error must not be nil.

func (*Group) Wait

func (g *Group) Wait() error

Wait blocks until the Group counter is zero. If no errors were recorded, it returns nil. If one error was recorded, it returns it as is. If more than one error was recorded it returns a MultiError which is a slice of errors.

type MultiError

type MultiError []error

MultiError allows returning a group of errors as one error.

func (MultiError) Error

func (m MultiError) Error() string

Error returns a concatenated string of all contained errors.

Source Files

Jump to

Keyboard shortcuts

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