diff options
| author | Jeff Carr <[email protected]> | 2024-01-03 18:13:10 -0600 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-03 18:13:10 -0600 | 
| commit | 9a975d82b89103d5a1cbd5710545679d8c20d722 (patch) | |
| tree | 8bd8922acf668cd5b9c444326d3da16a7ba6d557 | |
| parent | d0eb154fca63bdbbcf9f053ff7e8a44c916ef0c3 (diff) | |
TODO: switch to Ticker
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | ticker.go | 53 | 
1 files changed, 53 insertions, 0 deletions
diff --git a/ticker.go b/ticker.go new file mode 100644 index 0000000..6919207 --- /dev/null +++ b/ticker.go @@ -0,0 +1,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) +		i += 1 +		time.Sleep(watchtime * time.Second / 10) +	} +} +// https://www.reddit.com/r/golang/comments/12em87q/how_to_run_periodic_tasks/ +/* +package main + +import ( +	"fmt" +	"time" +) + +func main() { +	ticker := time.NewTicker(time.Second) +	defer ticker.Stop() +	done := make(chan bool) +	go func() { +		time.Sleep(10 * time.Second) +		done <- true +	}() +	for { +		select { +		case <-done: +			fmt.Println("Done!") +			return +		case t := <-ticker.C: +			fmt.Println("Current time: ", t) +		} +	} +} +*/  | 
