diff --git a/exegroup/group.go b/exegroup/group.go index 1a5ef3f..7af66d3 100644 --- a/exegroup/group.go +++ b/exegroup/group.go @@ -103,7 +103,7 @@ func (g *Group) validate() { } for _, actor := range g.actors { if actor.goFunc == nil { - panic(actor.name + "has nil goFunc") + panic(actor.name + " has nil goFunc") } } } @@ -131,12 +131,12 @@ func (g *Group) wait(c chan error, cancel context.CancelFunc) (err error) { ctx, cancel = context.WithTimeout(context.Background(), g.cfg.stopTimeout) defer cancel() } - for _, m := range g.actors { - if m.stopFunc != nil { + for i := len(g.actors) - 1; i >= 0; i-- { + if g.actors[i].stopFunc != nil { if g.cfg.concurrentStop { - go m.stopFunc(ctx) + go g.actors[i].stopFunc(ctx) } else { - m.stopFunc(ctx) + g.actors[i].stopFunc(ctx) } } }