virtigo/watchdog.go

39 lines
790 B
Go

package main
import (
"fmt"
"time"
"go.wit.com/log"
)
// timeFunction takes a function as an argument and returns the execution time.
func TimeFunction(f func()) time.Duration {
startTime := time.Now() // Record the start time
f() // Execute the function
return time.Since(startTime) // Calculate the elapsed time
}
func (h *HyperT) NewWatchdog() {
h.Dog = time.NewTicker(h.Delay)
defer h.Dog.Stop()
done := make(chan bool)
/*
// this example would exit/destroy the ticker in 10 seconds
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
*/
for {
select {
case <-done:
fmt.Println("Done!")
return
case t := <-h.Dog.C:
log.Log(POLL, "Watchdog() ticked", h.pb.Hostname, "Current time: ", t)
h.Scan()
}
}
}