package main import ( "fmt" "os" "time" ) // 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 NewWatchdog() { me.dog = time.NewTicker(me.pollDelay) defer me.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 _ = <-me.dog.C: // log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t) s := me.machine.UpdatePackages() // pingStatus() me.failcount += 1 sendMachine(s) if me.failcount > 20 { os.Exit(0) } // h.pollHypervisor() // h.Scan() } } }