Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

small refactorings

  • Loading branch information...
commit b96bc29984329674770e2ae60ef13297523fb3cd 1 parent c9f3a28
Jeffrey Hulten authored
Showing with 12 additions and 12 deletions.
  1. +12 −12 event.go
View
24 event.go
@@ -142,8 +142,10 @@ func (eventState *EventMonitoringState) monitorEvents(c *Client) {
timeout := time.After(100 * time.Millisecond)
select {
case ev := <-eventState.C:
- err = eventState.sendEvent(ev)
+ // send the event
+ go eventState.sendEvent(ev)
+ // update lastSeen if appropriate
go func(e *APIEvents) {
eventState.Lock()
defer eventState.Unlock()
@@ -152,38 +154,36 @@ func (eventState *EventMonitoringState) monitorEvents(c *Client) {
}
}(ev)
+ case err = <-eventState.errC:
if err == ErrNoListeners {
- eventState.RLock()
- defer eventState.RUnlock()
- eventState.disableEventMonitoring()
+ // if there are no listeners, exit normally
+ eventState.terminate(nil)
return
} else if err != nil {
- eventState.errC <- err
+ // otherwise, trigger a restart via the error channel
+ defer func() { go eventState.monitorEvents(c) }()
+ return
}
- case <-eventState.errC:
- defer func() { go eventState.monitorEvents(c) }()
- return
case <-timeout:
continue
}
}
}
-func (eventState *EventMonitoringState) sendEvent(event *APIEvents) error {
+func (eventState *EventMonitoringState) sendEvent(event *APIEvents) {
eventState.RLock()
defer eventState.RUnlock()
if len(eventState.listeners) == 0 {
- return ErrNoListeners
+ eventState.errC <- ErrNoListeners
}
for _, listener := range eventState.listeners {
listener <- event
}
- return nil
}
func (eventState *EventMonitoringState) terminate(err error) {
if err != nil {
- eventState.errC <- err
+ fmt.Printf("terminating montoring", err)
}
eventState.disableEventMonitoring()
}
Please sign in to comment.
Something went wrong with that request. Please try again.