wait

package module
v0.0.0-...-d0b1e9a Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: MIT Imports: 1 Imported by: 2

README

This package is deprecated

This package provides commonly-needed functionality and it saw use for several years. Today, though, new code should not use this package. Instead, use golang.org/x/sync/errgroup. Errgroup is a popular package and it has a nicer API for some use cases. It uses contexts for cancelation, which are the standard mechanism today. (The context package did not exist when github.com/cespare/wait was written.)

wait

GoDoc

wait is a Go package that provides Group, an extended version of sync.WaitGroup.

wait is similar to two other packages of which I'm aware:

  • tomb is a popular choice which is quite similar but has more features and a more complicated set of states (alive/dying/dead).
  • Camlistore has syncutil.Group which records multiple errors but does not support cancellation.

Documentation

Overview

Package wait provides Group, an extended version of sync.WaitGroup.

Deprecated: Use golang.org/x/sync/errgroup instead.

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
}

A Group waits for a collection of goroutines to exit. With Wait, one may wait for all goroutines to exit and get the first error that was seen. Cooperative cancellation is also supported via Quit and the broadcast chan passed to each goroutine. The zero value of Group is ready to be used.

func (*Group) Go

func (g *Group) Go(f func(quit <-chan struct{}) error)

Go runs f in a new goroutine. The quit chan is closed to indicate that f should exit early, so f is expected to periodically receive from quit and immediately return nil if a value arrives. Quit is called automatically if f returns a non-nil error.

func (*Group) Quit

func (g *Group) Quit()

Quit asks all goroutines started with Go to exit (by closing the quit chan given to each function). After the first call to Quit, subsequent calls have no effect.

func (*Group) Wait

func (g *Group) Wait() error

Wait waits for all goroutines to exit and returns the first non-nil error seen.

Jump to

Keyboard shortcuts

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