| 210 | } |
| 211 | |
| 212 | func (q *RequestQueue) stopping(_ error) error { |
| 213 | q.mtx.Lock() |
| 214 | defer q.mtx.Unlock() |
| 215 | |
| 216 | for q.queues.len() > 0 { |
| 217 | q.cond.Wait(context.Background()) |
| 218 | } |
| 219 | |
| 220 | // Only stop after dispatching enqueued requests. |
| 221 | q.stopped = true |
| 222 | |
| 223 | // If there are still goroutines in GetNextRequestForQuerier method, they get notified. |
| 224 | q.cond.Broadcast() |
| 225 | |
| 226 | return nil |
| 227 | } |
| 228 | |
| 229 | // contextCond is a *sync.Cond with Wait() method overridden to support context-based waiting. |
| 230 | type contextCond struct { |