mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-06-17 04:18:53 -04:00
The goutil that OpenCloud currently uses is one version from the release that adds FreeBSD support, this now compiles successfully on FreeBSD.
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package goutil
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gookit/goutil/structs"
|
|
"github.com/gookit/goutil/syncs"
|
|
)
|
|
|
|
// ErrGroup is a collection of goroutines working on subtasks that
|
|
// are part of the same overall task.
|
|
type ErrGroup = syncs.ErrGroup
|
|
|
|
// NewCtxErrGroup instance. use for batch run tasks, can with context.
|
|
//
|
|
// Deprecated: use syncs.NewCtxErrGroup instead
|
|
func NewCtxErrGroup(ctx context.Context, limit ...int) (*ErrGroup, context.Context) {
|
|
return syncs.NewCtxErrGroup(ctx, limit...)
|
|
}
|
|
|
|
// NewErrGroup instance. use for batch run tasks
|
|
//
|
|
// Deprecated: use syncs.NewErrGroup instead
|
|
func NewErrGroup(limit ...int) *ErrGroup {
|
|
return syncs.NewErrGroup(limit...)
|
|
}
|
|
|
|
// RunFn func
|
|
type RunFn func(ctx *structs.Data) error
|
|
|
|
// QuickRun struct
|
|
type QuickRun struct {
|
|
ctx *structs.Data
|
|
// err error
|
|
fns []RunFn
|
|
}
|
|
|
|
// NewQuickRun instance
|
|
func NewQuickRun() *QuickRun {
|
|
return &QuickRun{
|
|
ctx: structs.NewData(),
|
|
}
|
|
}
|
|
|
|
// Add func for run
|
|
func (p *QuickRun) Add(fns ...RunFn) *QuickRun {
|
|
p.fns = append(p.fns, fns...)
|
|
return p
|
|
}
|
|
|
|
// Run all func
|
|
func (p *QuickRun) Run() error {
|
|
for i, fn := range p.fns {
|
|
p.ctx.Set("_index", i)
|
|
if err := fn(p.ctx); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|