func runWorkers(ctx context.Context, workers int, jobs <-chan Job) error {
g, ctx := errgroup.WithContext(ctx)
for i := 0; i < workers; i++ {
g.Go(func() error {
for {
select {
case <-ctx.Done():
return ctx.Err()
case job, ok := <-jobs:
if !ok {
return nil
}
if err := processJob(ctx, job); err != nil {
return err
}
}
}
})
}
return g.Wait()
}
func runWorkers(ctx context.Context, workers int, jobs <-chan Job) error {
g, ctx := errgroup.WithContext(ctx)
for i := 0; i < workers; i++ {
g.Go(func() error {
for {
select {
case <-ctx.Done():
return ctx.Err()
case job, ok := <-jobs:
if !ok {
return nil
}
if err := processJob(ctx, job); err != nil {
return err
}
}
}
})
}
return g.Wait()
}