Pop removes and returns the first item from the queue, waiting until there is something to pop if necessary. If closed, returns false.
()
| 71 | // Pop removes and returns the first item from the queue, waiting until there is |
| 72 | // something to pop if necessary. If closed, returns false. |
| 73 | func (q *Queue[T]) Pop() (T, bool) { |
| 74 | var head T |
| 75 | q.mu.Lock() |
| 76 | defer q.mu.Unlock() |
| 77 | for len(q.items) == 0 && !q.closed { |
| 78 | q.cond.Wait() |
| 79 | } |
| 80 | if q.closed { |
| 81 | return head, false |
| 82 | } |
| 83 | head, q.items = q.items[0], q.items[1:] |
| 84 | return head, true |
| 85 | } |
| 86 | |
| 87 | func (q *Queue[T]) Len() int { |
| 88 | q.mu.Lock() |