Skip to content

Commit

Permalink
Sarthak | Runs each worker repeat number of times
Browse files Browse the repository at this point in the history
  • Loading branch information
SarthakMakhija committed Mar 27, 2024
1 parent f097cf9 commit 5203f7f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions workers/worker_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,20 @@ func (group *WorkerGroup) runWorkers(
return workers
}

//runs all the workers.
runWorkers := func(workers []Worker) *sync.WaitGroup {
var wg sync.WaitGroup
wg.Add(int(group.options.concurrency))

for _, worker := range workers {
worker.run(&wg)
//runs all the workers, each worker will be run "repeat" number of times.
//runWorkersAndWait will wait till all the workers are done in each run.
runWorkersAndWait := func(workers []Worker) {
for run := uint(1); run <= group.options.repeat; run++ {
var wg sync.WaitGroup
wg.Add(len(workers))

for _, worker := range workers {
worker.run(&wg)
}
wg.Wait()
}
return &wg
}
runWorkers(instantiateWorkers()).Wait()
runWorkersAndWait(instantiateWorkers())
group.doneChannel <- struct{}{}
}

Expand Down

0 comments on commit 5203f7f

Please sign in to comment.