// Parallel is a concurrent implementation of Executor type Parallel struct{} // Execute performs all provided actions in concurrently, failing closed on the // first error or if ctx is cancelled. func (p Parallel) Execute(ctx context.Context, actions []Action) error { grp, ctx := errgroup.WithContext(ctx) for _, a := range actions { grp.Go(p.execFn(ctx, a)) } return grp.Wait() } // execFn binds the Context and Action to the proper function signature for the // errgroup.Group. func (p Parallel) execFn(ctx context.Context, a Action) func() error { return func() error { return a.Execute(ctx) } }