blob: 07a1dee1fc2c44fbcd9aa1ff4c7af68daa5fc40c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package gui
import (
"time"
"go.wit.com/log"
)
var watchtime time.Duration = 100 // in tenths of seconds
/*
This program sits here.
If you exit here, the whole thing will os.Exit()
TODO: use Ticker
This goroutine can be used like a watchdog timer
*/
func Watchdog() {
var i = 1
/*
for {
log.Verbose("gui.Watchdog() is alive. give me something to do.", i)
time.Sleep(watchtime * time.Second / 10)
}
*/
// check the four known things to see if they are all WORKING
myTicker(3*time.Second, "WATCHDOG", func() {
i += 1
log.Log(INFO, "myTicker() ticked", i)
})
}
func myTicker(t time.Duration, name string, f func()) {
ticker := time.NewTicker(t)
defer ticker.Stop()
done := make(chan bool)
/*
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
*/
for {
select {
case <-done:
log.Warn("gui.Watchdog() Done!")
return
case t := <-ticker.C:
log.Log(INFO, name, "Current time: ", t)
f()
}
}
}
|