mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-04-18 11:39:11 -04:00
fix lint errors
This commit is contained in:
@@ -12,6 +12,16 @@ func executeAndFulfill(f func() error, done chan<- error) {
|
||||
close(done)
|
||||
}
|
||||
|
||||
// Execute runs a list of tasks sequentially, returns the first error encountered or nil if all tasks pass.
|
||||
func Execute(tasks ...func() error) error {
|
||||
for _, task := range tasks {
|
||||
if err := task(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExecuteAsync executes a function asynchronously and return its result.
|
||||
func ExecuteAsync(f func() error) <-chan error {
|
||||
done := make(chan error, 1)
|
||||
|
||||
@@ -11,6 +11,8 @@ type PeriodicTask struct {
|
||||
Interval time.Duration
|
||||
// Execute is the task function
|
||||
Execute func() error
|
||||
// OnFailure will be called when Execute returns non-nil error
|
||||
OnError func(error)
|
||||
|
||||
access sync.Mutex
|
||||
timer *time.Timer
|
||||
@@ -30,7 +32,9 @@ func (t *PeriodicTask) checkedExecute() error {
|
||||
}
|
||||
|
||||
t.timer = time.AfterFunc(t.Interval, func() {
|
||||
t.checkedExecute()
|
||||
if err := t.checkedExecute(); err != nil && t.OnError != nil {
|
||||
t.OnError(err)
|
||||
}
|
||||
})
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user