Pair returns the event linked to id, in either direction. If the given event has a CorrelatedID, that's the request it's paired with. Otherwise Pair walks the ring looking for an event whose CorrelatedID equals id — that would be its response. Returns (zero, false) when no link exists or the paired
(id uint64)
| 149 | // that would be its response. Returns (zero, false) when no link exists or |
| 150 | // the paired event has aged out of the ring. |
| 151 | func Pair(id uint64) (Event, bool) { |
| 152 | mu.Lock() |
| 153 | defer mu.Unlock() |
| 154 | var target Event |
| 155 | var have bool |
| 156 | for _, e := range events { |
| 157 | if e.ID == id { |
| 158 | target, have = e, true |
| 159 | break |
| 160 | } |
| 161 | } |
| 162 | if !have { |
| 163 | return Event{}, false |
| 164 | } |
| 165 | if target.CorrelatedID != 0 { |
| 166 | // Response → walk back to the request. |
| 167 | for _, e := range events { |
| 168 | if e.ID == target.CorrelatedID { |
| 169 | return e, true |
| 170 | } |
| 171 | } |
| 172 | return Event{}, false |
| 173 | } |
| 174 | // Request → walk forward to find a response that points back. |
| 175 | for _, e := range events { |
| 176 | if e.CorrelatedID == target.ID { |
| 177 | return e, true |
| 178 | } |
| 179 | } |
| 180 | return Event{}, false |
| 181 | } |
| 182 | |
| 183 | // FindByID returns the event with the given monotonic ID, if it's still in |
| 184 | // the ring. Used by /debug show to look up a specific event. |
no outgoing calls