all: use AbsTime.Add instead of conversion (#25417)

This commit is contained in:
Seungbae Yu
2022-07-29 18:23:30 +02:00
committed by GitHub
parent 9ad508018e
commit 029059947a
6 changed files with 11 additions and 11 deletions
+2 -2
View File
@@ -58,7 +58,7 @@ func (s *Simulated) Run(d time.Duration) {
s.mu.Lock()
s.init()
end := s.now + AbsTime(d)
end := s.now.Add(d)
var do []func()
for len(s.scheduled) > 0 && s.scheduled[0].at <= end {
ev := heap.Pop(&s.scheduled).(*simTimer)
@@ -134,7 +134,7 @@ func (s *Simulated) AfterFunc(d time.Duration, fn func()) Timer {
func (s *Simulated) schedule(d time.Duration, fn func()) *simTimer {
s.init()
at := s.now + AbsTime(d)
at := s.now.Add(d)
ev := &simTimer{do: fn, at: at, s: s}
heap.Push(&s.scheduled, ev)
s.cond.Broadcast()
+2 -2
View File
@@ -87,13 +87,13 @@ func (q *LazyQueue) Refresh() {
// refresh re-evaluates items in the older queue and swaps the two queues
func (q *LazyQueue) refresh(now mclock.AbsTime) {
q.maxUntil = now + mclock.AbsTime(q.period)
q.maxUntil = now.Add(q.period)
for q.queue[0].Len() != 0 {
q.Push(heap.Pop(q.queue[0]).(*item).value)
}
q.queue[0], q.queue[1] = q.queue[1], q.queue[0]
q.indexOffset = 1 - q.indexOffset
q.maxUntil += mclock.AbsTime(q.period)
q.maxUntil = q.maxUntil.Add(q.period)
}
// Push adds an item to the queue