Skip to content

Commit

Permalink
daemon/events: let Log be [slightly] blocking
Browse files Browse the repository at this point in the history
With go1.5's concurrency, the use of a goroutine in Log'ing events was
causing the resulting events to not be in order.

Signed-off-by: Vincent Batts <[email protected]>
  • Loading branch information
vbatts committed Sep 15, 2015
1 parent 59311fa commit 09e7dd0
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions daemon/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,17 @@ func (e *Events) Evict(l chan interface{}) {
// Log broadcasts event to listeners. Each listener has 100 millisecond for
// receiving event or it will be skipped.
func (e *Events) Log(action, id, from string) {
go func() {
e.mu.Lock()
jm := &jsonmessage.JSONMessage{Status: action, ID: id, From: from, Time: time.Now().UTC().Unix()}
if len(e.events) == cap(e.events) {
// discard oldest event
copy(e.events, e.events[1:])
e.events[len(e.events)-1] = jm
} else {
e.events = append(e.events, jm)
}
e.mu.Unlock()
e.pub.Publish(jm)
}()
jm := &jsonmessage.JSONMessage{Status: action, ID: id, From: from, Time: time.Now().UTC().Unix()}
e.mu.Lock()
if len(e.events) == cap(e.events) {
// discard oldest event
copy(e.events, e.events[1:])
e.events[len(e.events)-1] = jm
} else {
e.events = append(e.events, jm)
}
e.mu.Unlock()
e.pub.Publish(jm)
}

// SubscribersCount returns number of event listeners
Expand Down

0 comments on commit 09e7dd0

Please sign in to comment.