Dequeue will remove and return the op with the highest priority; block if queue is empty; returns nil if queue is closed.
()
| 100 | // Dequeue will remove and return the op with the highest priority; block if queue is |
| 101 | // empty; returns nil if queue is closed. |
| 102 | func (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 |
| 123 | func (pq *PriorityQueue) Peek() PriorityOp { |