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
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.
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.
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.
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.