Cleanup queue in time

pull/40/head
V2Ray 9 years ago
parent ab151cc053
commit 7fe9683f28

@ -71,8 +71,7 @@ func (queue *TimedQueue) RemovedEntries() <-chan interface{} {
}
func (queue *TimedQueue) cleanup(tick <-chan time.Time) {
for {
now := <-tick
for now := range tick {
queue.access.RLock()
queueLen := queue.queue.Len()
queue.access.RUnlock()
@ -80,16 +79,18 @@ func (queue *TimedQueue) cleanup(tick <-chan time.Time) {
continue
}
nowSec := now.UTC().Unix()
for {
queue.access.RLock()
firstEntryTime := queue.queue[0].timeSec
entry := queue.queue[0]
queue.access.RUnlock()
if firstEntryTime > nowSec {
continue
if entry.timeSec > nowSec {
break
}
queue.access.Lock()
firstEntryValue := heap.Pop(&queue.queue).(*timedQueueEntry).value
heap.Pop(&queue.queue)
queue.access.Unlock()
queue.removed <- firstEntryValue
queue.removed <- entry.value
}
}
}

Loading…
Cancel
Save