Skip to content

Commit

Permalink
project: introduce semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
haya14busa committed Dec 16, 2016
1 parent 2a2d82c commit 8127a16
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions project/run.go
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"os/exec"
"runtime"

"golang.org/x/sync/errgroup"

Expand All @@ -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
Expand All @@ -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))
})
}
Expand Down

0 comments on commit 8127a16

Please sign in to comment.