Subscribe returns: - a subscription ID that can be used to unsubscribe. - a channel for receiving events. - a list of events that allow to recreate the state of the conversation right before the subscription was created.
()
| 270 | // - a channel for receiving events. |
| 271 | // - a list of events that allow to recreate the state of the conversation right before the subscription was created. |
| 272 | func (e *EventEmitter) Subscribe() (int, <-chan Event, []Event) { |
| 273 | e.mu.Lock() |
| 274 | defer e.mu.Unlock() |
| 275 | stateEvents := e.currentStateAsEvents() |
| 276 | |
| 277 | // Once a channel becomes full, it will be closed. |
| 278 | ch := make(chan Event, e.subscriptionBufSize) |
| 279 | e.chans[e.chanIdx] = ch |
| 280 | e.chanIdx++ |
| 281 | return e.chanIdx - 1, ch, stateEvents |
| 282 | } |
| 283 | |
| 284 | // Assumes the caller holds the lock. |
| 285 | func (e *EventEmitter) unsubscribeInner(chanId int) { |