Enqueue adds an operation to the queue in priority order.
(op PriorityOp)
| 83 | |
| 84 | // Enqueue adds an operation to the queue in priority order. |
| 85 | func (pq *PriorityQueue) Enqueue(op PriorityOp) { |
| 86 | pq.lock.Lock() |
| 87 | defer pq.lock.Unlock() |
| 88 | |
| 89 | if pq.closing || pq.closed { |
| 90 | panic("enqueue on closed queue") |
| 91 | } |
| 92 | |
| 93 | heap.Push(&pq.queue, op) |
| 94 | pq.cond.Broadcast() |
| 95 | if pq.lengthGauge != nil { |
| 96 | pq.lengthGauge.Inc() |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // Dequeue will remove and return the op with the highest priority; block if queue is |
| 101 | // empty; returns nil if queue is closed. |