Improve task

This commit is contained in:
世界 2022-08-03 17:07:57 +08:00
parent afbe231237
commit d9ca259bec
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
4 changed files with 128 additions and 152 deletions

View file

@ -0,0 +1,26 @@
package task
import "context"
func Run(ctx context.Context, tasks ...func() error) error {
var group Group
for _, task := range tasks {
currentTask := task
group.Append0(func(ctx context.Context) error {
return currentTask()
})
}
return group.Run(ctx)
}
func Any(ctx context.Context, tasks ...func(ctx context.Context) error) error {
var group Group
for _, task := range tasks {
currentTask := task
group.Append0(func(ctx context.Context) error {
return currentTask(ctx)
})
}
group.FastFail()
return group.Run(ctx)
}