1
0
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:
Darien Raymond
2018-04-11 16:15:29 +02:00
parent 044c641d7b
commit 9d7f43a299
11 changed files with 87 additions and 66 deletions

View File

@@ -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)

View File

@@ -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