chore: improve ticker
This commit is contained in:
parent
597eeeb4dc
commit
b172eb2a46
1 changed files with 4 additions and 6 deletions
|
|
@ -47,16 +47,14 @@ func NewWatchDogFromConfig(ctx context.Context, other map[string]interface{}) (P
|
|||
}
|
||||
|
||||
func (o *watchdogProvider) wdt(ctx context.Context, set func() error) {
|
||||
tick := time.NewTicker(o.timeout / 2)
|
||||
for range tick.C {
|
||||
for tick := time.Tick(o.timeout); ; {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
tick.Stop()
|
||||
return
|
||||
default:
|
||||
case <-tick:
|
||||
if err := set(); err != nil {
|
||||
o.log.ERROR.Println(err)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue