MCPcopy Create free account
hub / github.com/cortexproject/cortex / Dequeue

Method Dequeue

pkg/util/priority_queue.go:102–120  ·  view source on GitHub ↗

Dequeue will remove and return the op with the highest priority; block if queue is empty; returns nil if queue is closed.

()

Source from the content-addressed store, hash-verified

100// Dequeue will remove and return the op with the highest priority; block if queue is
101// empty; returns nil if queue is closed.
102func (pq *PriorityQueue) Dequeue() PriorityOp {
103 pq.lock.Lock()
104 defer pq.lock.Unlock()
105
106 for len(pq.queue) == 0 && (!pq.closing && !pq.closed) {
107 pq.cond.Wait()
108 }
109
110 if len(pq.queue) == 0 && (pq.closing || pq.closed) {
111 pq.closed = true
112 return nil
113 }
114
115 op := heap.Pop(&pq.queue).(PriorityOp)
116 if pq.lengthGauge != nil {
117 pq.lengthGauge.Dec()
118 }
119 return op
120}
121
122// Peek will return the op with the highest priority without removing it from the queue
123func (pq *PriorityQueue) Peek() PriorityOp {

Callers 6

TestPriorityQueueBasicFunction · 0.95
TestPriorityQueueWaitFunction · 0.95
TestPriorityQueueCloseFunction · 0.95
dequeueRequestMethod · 0.80

Calls 3

DecMethod · 0.80
WaitMethod · 0.45
PopMethod · 0.45

Tested by 5

TestPriorityQueueBasicFunction · 0.76
TestPriorityQueueWaitFunction · 0.76
TestPriorityQueueCloseFunction · 0.76