...
1 package main
2
3 import (
4 "flag"
5 "fmt"
6 "golang.conradwood.net/go-easyops/utils"
7 "time"
8 )
9
10 func main() {
11 flag.Parse()
12 fmt.Printf("h\n")
13 testTimer([]uint32{30, 15, 10, 5})
14 }
15 func testTimer(secs []uint32) {
16 var sd []time.Duration
17 for _, s := range secs {
18 sd = append(sd, time.Duration(s)*time.Second)
19 }
20 pt := utils.NewPeriodicTimer(sd, timerCallback)
21 pt.Start()
22 pt.Wait()
23 }
24 func timerCallback(pt *utils.PeriodicTimer, secsLapsed time.Duration) error {
25 sc := time.Since(pt.LastStarted()).Seconds()
26 desc := fmt.Sprintf("%v", pt.Secs())
27 fmt.Printf("timercallback (%s) after %0.1fs (%0.1fs)\n", desc, sc, secsLapsed.Seconds())
28 if (sc >= 9) && (sc < 17) {
29 return fmt.Errorf("foo")
30 }
31 return nil
32 }
33
View as plain text