mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 06:46:34 +00:00
repository: Simplify worker group code
This commit is contained in:
parent
84ea2389ae
commit
4784540f04
@ -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
|
||||
|
@ -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
|
||||
|
@ -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++ {
|
||||
|
Loading…
Reference in New Issue
Block a user