mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-05 04:47:40 +03:00
Improve task
This commit is contained in:
parent
afbe231237
commit
d9ca259bec
4 changed files with 128 additions and 152 deletions
26
common/task/task_deprecated.go
Normal file
26
common/task/task_deprecated.go
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue