|
@@ -20,7 +20,7 @@ type token struct{}
|
|
|
// A zero Group is valid, has no limit on the number of active goroutines,
|
|
|
// and does not cancel on error.
|
|
|
type Group struct {
|
|
|
- cancel func()
|
|
|
+ cancel func(error)
|
|
|
|
|
|
wg sync.WaitGroup
|
|
|
|
|
@@ -43,7 +43,7 @@ func (g *Group) done() {
|
|
|
// returns a non-nil error or the first time Wait returns, whichever occurs
|
|
|
// first.
|
|
|
func WithContext(ctx context.Context) (*Group, context.Context) {
|
|
|
- ctx, cancel := context.WithCancel(ctx)
|
|
|
+ ctx, cancel := withCancelCause(ctx)
|
|
|
return &Group{cancel: cancel}, ctx
|
|
|
}
|
|
|
|
|
@@ -52,7 +52,7 @@ func WithContext(ctx context.Context) (*Group, context.Context) {
|
|
|
func (g *Group) Wait() error {
|
|
|
g.wg.Wait()
|
|
|
if g.cancel != nil {
|
|
|
- g.cancel()
|
|
|
+ g.cancel(g.err)
|
|
|
}
|
|
|
return g.err
|
|
|
}
|
|
@@ -76,7 +76,7 @@ func (g *Group) Go(f func() error) {
|
|
|
g.errOnce.Do(func() {
|
|
|
g.err = err
|
|
|
if g.cancel != nil {
|
|
|
- g.cancel()
|
|
|
+ g.cancel(g.err)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -105,7 +105,7 @@ func (g *Group) TryGo(f func() error) bool {
|
|
|
g.errOnce.Do(func() {
|
|
|
g.err = err
|
|
|
if g.cancel != nil {
|
|
|
- g.cancel()
|
|
|
+ g.cancel(g.err)
|
|
|
}
|
|
|
})
|
|
|
}
|