repository: Simplify worker group code

This commit is contained in:
Michael Eischer 2020-03-08 20:48:51 +01:00
parent 84ea2389ae
commit 4784540f04
3 changed files with 4 additions and 6 deletions

View file

@ -142,7 +142,7 @@ func (c *Checker) LoadIndex(ctx context.Context) (hints []error, errs []error) {
// run workers on ch
wg.Go(func() error {
return repository.RunWorkers(ctx, defaultParallelism, worker, final)
return repository.RunWorkers(defaultParallelism, worker, final)
})
// receive decoded indexes

View file

@ -479,7 +479,7 @@ func (r *Repository) LoadIndex(ctx context.Context) error {
// run workers on ch
wg.Go(func() error {
return RunWorkers(ctx, loadIndexParallelism, worker, final)
return RunWorkers(loadIndexParallelism, worker, final)
})
// receive decoded indexes

View file

@ -1,8 +1,6 @@
package repository
import (
"context"
"golang.org/x/sync/errgroup"
)
@ -10,8 +8,8 @@ import (
// After all workers have terminated, finalFunc is run. If an error occurs in
// one of the workers, it is returned. FinalFunc is always run, regardless of
// any other previous errors.
func RunWorkers(ctx context.Context, count int, workerFunc func() error, finalFunc func()) error {
wg, _ := errgroup.WithContext(ctx)
func RunWorkers(count int, workerFunc func() error, finalFunc func()) error {
var wg errgroup.Group
// run workers
for i := 0; i < count; i++ {