diff --git a/errgroup.go b/errgroup.go index e40a4d0..39605d3 100644 --- a/errgroup.go +++ b/errgroup.go @@ -154,13 +154,20 @@ func (g *Group) Go(f func() error) { return } - g.qCh <- f - - // Check if we can or should start a new goroutine? - g.maybeStartG() + for { + if g.err != nil { + g.qMu.Unlock() + return + } - g.qMu.Unlock() + select { + case g.qCh <- f: + g.maybeStartG() + g.qMu.Unlock() + return + } + } } // maybeStartG might start a new worker goroutine, if