summaryrefslogtreecommitdiff
path: root/watchdog.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-09 00:53:36 -0600
committerJeff Carr <[email protected]>2025-03-09 00:53:36 -0600
commitb7003bbc767a66e2285c8d1c3b5a068a63af0efe (patch)
tree76a26f90c0e7e78fbfc2b440edbec76c03827aa7 /watchdog.go
day #1v0.0.0
Diffstat (limited to 'watchdog.go')
-rw-r--r--watchdog.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/watchdog.go b/watchdog.go
new file mode 100644
index 0000000..9384f00
--- /dev/null
+++ b/watchdog.go
@@ -0,0 +1,41 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+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 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:
+ t := time.Now()
+ log.Info("Watchdog() ticked Current time: ", t)
+ }
+ }
+}