Simplify proxy NAT checking logic

This commit is contained in:
itchyonion 2024-05-17 14:26:21 -07:00
parent 54495ceb4e
commit 4ed5da7f2f
No known key found for this signature in database
GPG key ID: 4B87B720348500EA
2 changed files with 44 additions and 47 deletions

View file

@ -36,6 +36,8 @@ type Periodic struct {
Interval time.Duration
// Execute is the task function
Execute func() error
// OnError handles the error of the task
OnError func(error)
access sync.Mutex
timer *time.Timer
@ -55,10 +57,15 @@ func (t *Periodic) checkedExecute() error {
}
if err := t.Execute(); err != nil {
t.access.Lock()
t.running = false
t.access.Unlock()
return err
if t.OnError != nil {
t.OnError(err)
} else {
// default error handling is to shut down the task
t.access.Lock()
t.running = false
t.access.Unlock()
return err
}
}
t.access.Lock()