Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.3 to 2.2.4. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.2.3...v2.2.4) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
47 lines
915 B
Go
47 lines
915 B
Go
package syncs
|
|
|
|
import (
|
|
"context"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
)
|
|
|
|
// ErrGroup is a collection of goroutines working on subtasks that
|
|
// are part of the same overall task.
|
|
//
|
|
// Refers:
|
|
//
|
|
// https://github.com/neilotoole/errgroup
|
|
// https://github.com/fatih/semgroup
|
|
type ErrGroup struct {
|
|
*errgroup.Group
|
|
}
|
|
|
|
// NewCtxErrGroup instance
|
|
func NewCtxErrGroup(ctx context.Context, limit ...int) (*ErrGroup, context.Context) {
|
|
egg, ctx1 := errgroup.WithContext(ctx)
|
|
if len(limit) > 0 && limit[0] > 0 {
|
|
egg.SetLimit(limit[0])
|
|
}
|
|
|
|
eg := &ErrGroup{Group: egg}
|
|
return eg, ctx1
|
|
}
|
|
|
|
// NewErrGroup instance
|
|
func NewErrGroup(limit ...int) *ErrGroup {
|
|
eg := &ErrGroup{Group: new(errgroup.Group)}
|
|
|
|
if len(limit) > 0 && limit[0] > 0 {
|
|
eg.SetLimit(limit[0])
|
|
}
|
|
return eg
|
|
}
|
|
|
|
// Add one or more handler at once
|
|
func (g *ErrGroup) Add(handlers ...func() error) {
|
|
for _, handler := range handlers {
|
|
g.Go(handler)
|
|
}
|
|
}
|