Skip to content

Commit

Permalink
Add: upper limit of concurrency (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho authored Sep 25, 2021
1 parent 9d2cfab commit 469236b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"strings"

"golang.org/x/sync/semaphore"

"golang.org/x/sync/errgroup"

"github.com/sanposhiho/gomockhandler/internal/mockgen"
Expand Down Expand Up @@ -38,11 +41,14 @@ func (r Runner) Check() {

isFail := false
g, _ := errgroup.WithContext(ctx)
sem := semaphore.NewWeighted(int64(runtime.GOMAXPROCS(0)))
for _, m := range ch.Mocks {
m := m
sem.Acquire(ctx, 1)

var runner mockgen.Runner
g.Go(func() error {
defer sem.Release(1)
switch m.Mode {
case model.ReflectMode:
runner = m.ReflectModeRunner
Expand Down
7 changes: 7 additions & 0 deletions internal/command/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"strings"

"golang.org/x/sync/semaphore"

"github.com/sanposhiho/gomockhandler/internal/mockgen"

"github.com/sanposhiho/gomockhandler/internal/model"
Expand All @@ -31,9 +34,13 @@ func (r Runner) Mockgen() {
}

g, _ := errgroup.WithContext(context.Background())
sem := semaphore.NewWeighted(int64(runtime.GOMAXPROCS(0)))
for _, m := range ch.Mocks {
m := m
sem.Acquire(context.Background(), 1)

g.Go(func() error {
defer sem.Release(1)
var runner mockgen.Runner
var sourceChecksum string
switch m.Mode {
Expand Down

0 comments on commit 469236b

Please sign in to comment.