Skip to content

Commit d5e9b5f

Browse files
authored
calculate # of concurrency only once at the runner (#6506)
Signed-off-by: SungJin1212 <[email protected]>
1 parent 03a8f8c commit d5e9b5f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pkg/util/concurrency/runner.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ func ForEachUser(ctx context.Context, userIDs []string, concurrency int, userFun
2929
errsMx := sync.Mutex{}
3030

3131
wg := sync.WaitGroup{}
32-
for ix := 0; ix < min(concurrency, len(userIDs)); ix++ {
32+
routines := min(concurrency, len(userIDs))
33+
for ix := 0; ix < routines; ix++ {
3334
wg.Add(1)
3435
go func() {
3536
defer wg.Done()
@@ -75,7 +76,8 @@ func ForEach(ctx context.Context, jobs []interface{}, concurrency int, jobFunc f
7576

7677
// Start workers to process jobs.
7778
g, ctx := errgroup.WithContext(ctx)
78-
for ix := 0; ix < min(concurrency, len(jobs)); ix++ {
79+
routines := min(concurrency, len(jobs))
80+
for ix := 0; ix < routines; ix++ {
7981
g.Go(func() error {
8082
for job := range ch {
8183
if err := ctx.Err(); err != nil {

0 commit comments

Comments
 (0)