Adds async events to the channel for processing
(ctx context.Context, event Event)
| 140 | |
| 141 | // Adds async events to the channel for processing |
| 142 | func (em *EventManager) raiseEvent(ctx context.Context, event Event) error { |
| 143 | if !event.Synchronous() { |
| 144 | // When asyncEventChannel is full, the raiseEvent method will block for (waitTime). |
| 145 | // Default value of (waitTime) is 5 ms. |
| 146 | timer := time.NewTimer(time.Duration(em.waitTime) * time.Millisecond) |
| 147 | defer timer.Stop() |
| 148 | select { |
| 149 | case em.asyncEventChannel <- event: |
| 150 | base.TracefCtx(ctx, base.KeyAll, "Event sent to channel %s", event.String()) |
| 151 | case <-timer.C: |
| 152 | // Event queue channel is full - ignore event and log error |
| 153 | base.WarnfCtx(ctx, "Event queue full - discarding event: %s", base.UD(event.String())) |
| 154 | return errors.New("Event queue full") |
| 155 | } |
| 156 | } |
| 157 | // TODO: handling for synchronous events |
| 158 | return nil |
| 159 | } |
| 160 | |
| 161 | // Raises a document change event based on the the document body and channel set. If the |
| 162 | // event manager doesn't have a listener for this event, ignores. |