-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (39 loc) · 881 Bytes
/
main.go
File metadata and controls
49 lines (39 loc) · 881 Bytes
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
package main
import (
"os"
"fmt"
"time"
"os/signal"
"syscall"
"timeloop/timer"
)
var (
timerCtl *timer.TimerHeapHandler
asyncWorker int = 10
)
func init() {
timerCtl = timer.New(10, 1000)
}
type timerHandler struct {
}
func AddTimerTask(dueInterval int, taskId string) {
timerCtl.AddFuncWithId(time.Duration(dueInterval)*time.Second, taskId, func() {
fmt.Printf("taskid is %v, time Duration is %v", taskId, dueInterval )
})
}
func (t *timerHandler) StartLoop() {
timerCtl.StartTimerLoop(timer.MIN_TIMER) // 扫描的间隔时间 eq cpu hz/tick
}
func (t *timerHandler) Exit(sigs chan os.Signal) {
// graceful exit
<- sigs
fmt.Println("timer will exit")
timerCtl.Exit()
}
func main() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
timerEntry := timerHandler{}
timerEntry.StartLoop()
timerEntry.Exit(sigs)
}