Skip to content

Commit

Permalink
Re-check active before deactivating at the end of Wait.
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Mar 19, 2024
1 parent 4111682 commit b464644
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions taskgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ func New(ef ErrorFunc) *Group { return &Group{onError: ef} }

// Go runs task in a new goroutine in g, and returns g to permit chaining.
func (g *Group) Go(task Task) *Group {
g.wg.Add(1)
if g.active.Load() == 0 {
g.activate()
}
g.wg.Add(1)
go func() {
defer g.wg.Done()
if err := task(); err != nil {
Expand Down Expand Up @@ -94,7 +94,11 @@ func (g *Group) Wait() error {
g.wg.Wait()
g.μ.Lock()
defer g.μ.Unlock()
defer g.active.Store(0)

// If the group is still active, deactivate it now.
if g.active.Load() != 0 {
g.active.Store(0)
}
return g.err
}

Expand Down

0 comments on commit b464644

Please sign in to comment.