mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Simplify proxy NAT checking logic
This commit is contained in:
parent
54495ceb4e
commit
4ed5da7f2f
2 changed files with 44 additions and 47 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue