mirror of
https://github.com/genxium/DelayNoMore
synced 2024-12-27 12:08:21 +00:00
28 lines
401 B
Go
28 lines
401 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type Watchdog struct {
|
|
interval time.Duration
|
|
timer *time.Timer
|
|
}
|
|
|
|
func NewWatchdog(interval time.Duration, callback func()) *Watchdog {
|
|
w := Watchdog{
|
|
interval: interval,
|
|
timer: time.AfterFunc(interval, callback),
|
|
}
|
|
return &w
|
|
}
|
|
|
|
func (w *Watchdog) Stop() {
|
|
w.timer.Stop()
|
|
}
|
|
|
|
func (w *Watchdog) Kick() {
|
|
w.timer.Stop()
|
|
w.timer.Reset(w.interval)
|
|
}
|