Skip to content

Commit

Permalink
add a precondition before heap operations
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed May 26, 2017
1 parent 7f81f73 commit 8ed1e5b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,19 @@ func (h *updateHeap) updateTask() {
h.mu.Lock()
hlen := h.Len()
now := time.Now()
for i := 0; i < hlen; i++ {
entry := heap.Pop(h).(entry)
if now.After(entry.ts) {
entry.ts = now.Add(entry.s.update())
heap.Push(h, entry)
} else {
heap.Push(h, entry)
break
if hlen > 0 && now.After(h.entries[0].ts) {
for i := 0; i < hlen; i++ {
entry := heap.Pop(h).(entry)
if now.After(entry.ts) {
entry.ts = now.Add(entry.s.update())
heap.Push(h, entry)
} else {
heap.Push(h, entry)
break
}
}
}
if h.Len() > 0 {
if hlen > 0 {
timer = time.After(h.entries[0].ts.Sub(now))
}
h.mu.Unlock()
Expand Down

0 comments on commit 8ed1e5b

Please sign in to comment.