| 218 | } |
| 219 | |
| 220 | func (e *EventEmitter) EmitError(message string, level st.ErrorLevel) { |
| 221 | e.mu.Lock() |
| 222 | defer e.mu.Unlock() |
| 223 | |
| 224 | errorBody := ErrorBody{ |
| 225 | Message: message, |
| 226 | Level: level, |
| 227 | Time: e.clock.Now(), |
| 228 | } |
| 229 | |
| 230 | // Store the error so new subscribers can receive recent errors. |
| 231 | e.errors = append(e.errors, errorBody) |
| 232 | if len(e.errors) > maxStoredErrors { |
| 233 | e.errors = e.errors[len(e.errors)-maxStoredErrors:] |
| 234 | } |
| 235 | |
| 236 | e.notifyChannels(EventTypeError, errorBody) |
| 237 | } |
| 238 | |
| 239 | // Assumes the caller holds the lock. |
| 240 | func (e *EventEmitter) currentStateAsEvents() []Event { |