Permalink
Browse files

project: introduce semaphore

  • Loading branch information...
1 parent 05a071a commit 039894982380cdebc4da578e3bd94fbc36e54016 @haya14busa committed Dec 16, 2016
Showing with 4 additions and 0 deletions.
  1. +4 −0 project/run.go
View
@@ -6,6 +6,7 @@ import (
"io"
"os"
"os/exec"
+ "runtime"
"golang.org/x/sync/errgroup"
@@ -17,7 +18,9 @@ func Run(ctx context.Context, conf *Config, c reviewdog.CommentService, d review
// environment variables for each commands
envs := filteredEnviron()
var g errgroup.Group
+ semaphore := make(chan int, runtime.NumCPU())
for _, runner := range conf.Runner {
+ semaphore <- 1
fname := runner.Format
if fname == "" && len(runner.Errorformat) == 0 {
fname = runner.Name
@@ -39,6 +42,7 @@ func Run(ctx context.Context, conf *Config, c reviewdog.CommentService, d review
return fmt.Errorf("fail to start command: %v", err)
}
g.Go(func() error {
+ defer func() { <-semaphore }()
return rd.Run(io.MultiReader(stdout, stderr))
})
}

0 comments on commit 0398949

Please sign in to comment.