优化定时器

This commit is contained in:
boyce
2020-12-15 18:02:35 +08:00
parent fbd79d90f9
commit 99d968bc67
3 changed files with 22 additions and 7 deletions

View File

@@ -14,6 +14,17 @@ func SetupTimer(timer *Timer) *Timer{
return timer
}
func NewTimer(d time.Duration) *Timer{
c := make(chan *Timer,1)
timer := newTimer(d,c,nil,"",nil)
SetupTimer(timer)
return timer
}
func ReleaseTimer(timer *Timer) {
releaseTimer(timer)
}
type _TimerHeap struct {
timers []*Timer
}

View File

@@ -89,6 +89,11 @@ func (t *Timer) Do(){
}
}
func (t *Timer) SetupTimer(now time.Time){
t.fireTime = now.Add(t.interval)
SetupTimer(t)
}
func (t *Timer) GetInterval() time.Duration{
return t.interval
}