Assumes the caller holds the lock.
(eventType EventType, payload any)
| 139 | |
| 140 | // Assumes the caller holds the lock. |
| 141 | func (e *EventEmitter) notifyChannels(eventType EventType, payload any) { |
| 142 | chanIds := make([]int, 0, len(e.chans)) |
| 143 | for chanId := range e.chans { |
| 144 | chanIds = append(chanIds, chanId) |
| 145 | } |
| 146 | for _, chanId := range chanIds { |
| 147 | ch := e.chans[chanId] |
| 148 | event := Event{ |
| 149 | Type: eventType, |
| 150 | Payload: payload, |
| 151 | } |
| 152 | |
| 153 | select { |
| 154 | case ch <- event: |
| 155 | default: |
| 156 | // If the channel is full, close it. |
| 157 | // Listeners must actively drain the channel. |
| 158 | e.unsubscribeInner(chanId) |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // EmitMessages assumes that only the last message can change or new messages can be added. |
| 164 | // If a new message is injected between existing messages (identified by Id), the behavior is undefined. |
no test coverage detected