Close gracefully shuts down the queue, waiting for pending messages to be processed.
()
| 87 | |
| 88 | // Close gracefully shuts down the queue, waiting for pending messages to be processed. |
| 89 | func (q *Queue[T]) Close() { |
| 90 | q.mu.Lock() |
| 91 | if q.closed { |
| 92 | q.mu.Unlock() |
| 93 | return |
| 94 | } |
| 95 | q.closed = true |
| 96 | q.mu.Unlock() |
| 97 | |
| 98 | close(q.queue) |
| 99 | q.wg.Wait() |
| 100 | log.Infof("[%s] queue closed", q.name) |
| 101 | } |
| 102 | |
| 103 | // startWorker starts the background goroutine that processes messages. |
| 104 | func (q *Queue[T]) startWorker() { |