From 828d0d759e577040f219154cd67cc8b01d1c26ea Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Tue, 17 Oct 2023 07:29:32 -0400 Subject: [PATCH] Use errgroup limiter where appropriate (#2926) * make use of errgroup.SetLimit * here too * gofmt --- src/format/fmt.go | 4 +--- src/run/run_step.go | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/format/fmt.go b/src/format/fmt.go index 80acbb9f49..cd15c50c9e 100644 --- a/src/format/fmt.go +++ b/src/format/fmt.go @@ -41,12 +41,10 @@ func Format(config *core.Configuration, filenames []string, rewrite, quiet bool) func formatAll(filenames <-chan string, parallelism int, rewrite, quiet bool) (bool, error) { var changed int64 var g errgroup.Group - limiter := make(chan struct{}, parallelism) + g.SetLimit(parallelism) for filename := range filenames { filename := filename g.Go(func() error { - limiter <- struct{}{} - defer func() { <-limiter }() c, err := format(filename, rewrite, quiet) if c { atomic.AddInt64(&changed, 1) diff --git a/src/run/run_step.go b/src/run/run_step.go index e17bebb51a..fe24d4b6c5 100644 --- a/src/run/run_step.go +++ b/src/run/run_step.go @@ -38,14 +38,11 @@ func Run(state *core.BuildState, label core.AnnotatedOutputLabel, args []string, func Parallel(ctx context.Context, state *core.BuildState, labels []core.AnnotatedOutputLabel, args []string, numTasks int, outputMode process.OutputMode, remote, env, detach, inTmp bool, dir string) int { prepareRun() - limiter := make(chan struct{}, numTasks) var g errgroup.Group + g.SetLimit(numTasks) for _, label := range labels { label := label // capture locally g.Go(func() error { - limiter <- struct{}{} - defer func() { <-limiter }() - err := runWithOutput(ctx, state, label, args, outputMode, remote, env, detach, inTmp, dir) if err != nil && ctx.Err() == nil { log.Error("Command failed: %s", err)