| 122 | } |
| 123 | |
| 124 | func (h *handlerNotifier) EnqueueCandidate(cand Candidate) { |
| 125 | h.Lock() |
| 126 | defer h.Unlock() |
| 127 | |
| 128 | select { |
| 129 | case <-h.done: |
| 130 | return |
| 131 | default: |
| 132 | } |
| 133 | |
| 134 | notify := func() { |
| 135 | defer h.notifiers.Done() |
| 136 | for { |
| 137 | h.Lock() |
| 138 | if len(h.candidates) == 0 { |
| 139 | h.runningCandidates = false |
| 140 | h.Unlock() |
| 141 | |
| 142 | return |
| 143 | } |
| 144 | notification := h.candidates[0] |
| 145 | h.candidates = h.candidates[1:] |
| 146 | h.Unlock() |
| 147 | h.candidateFunc(notification) |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | h.candidates = append(h.candidates, cand) |
| 152 | if !h.runningCandidates { |
| 153 | h.runningCandidates = true |
| 154 | h.notifiers.Add(1) |
| 155 | go notify() |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | func (h *handlerNotifier) EnqueueSelectedCandidatePair(pair *CandidatePair) { |
| 160 | h.Lock() |