DequeueByPriority removes the next item in the given priority level and returns it.
(priority uint8)
| 186 | // DequeueByPriority removes the next item in the given priority level |
| 187 | // and returns it. |
| 188 | func (pq *PriorityQueue) DequeueByPriority(priority uint8) (*PriorityItem, error) { |
| 189 | pq.Lock() |
| 190 | defer pq.Unlock() |
| 191 | |
| 192 | // Check if queue is closed. |
| 193 | if !pq.isOpen { |
| 194 | return nil, ErrDBClosed |
| 195 | } |
| 196 | |
| 197 | // Try to get the next item in the given priority level. |
| 198 | item, err := pq.getItemByPriorityID(priority, pq.levels[priority].head+1) |
| 199 | if err != nil { |
| 200 | return nil, err |
| 201 | } |
| 202 | |
| 203 | // Remove this item from the priority queue. |
| 204 | if err = pq.db.Delete(item.Key, nil); err != nil { |
| 205 | return nil, err |
| 206 | } |
| 207 | |
| 208 | // Increment head position. |
| 209 | pq.levels[priority].head++ |
| 210 | |
| 211 | return item, nil |
| 212 | } |
| 213 | |
| 214 | // Peek returns the next item in the priority queue without removing it. |
| 215 | func (pq *PriorityQueue) Peek() (*PriorityItem, error) { |