Skip to content

Commit

Permalink
simplify logch goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbailey committed Nov 5, 2019
1 parent 1585179 commit 8ccb770
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions command/agent/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,32 @@ func (d *monitor) Start() <-chan []byte {
d.logger.RegisterSink(d.sink)

streamCh := make(chan []byte, d.bufSize)

// run a go routine that listens for streamed
// log messages and sends them to streamCh
go func() {
defer close(streamCh)
defer func() {
d.logger.DeregisterSink(d.sink)
close(streamCh)
}()

for {
select {
case log := <-d.logCh:
select {
case <-d.doneCh:
d.logger.DeregisterSink(d.sink)
close(d.logCh)
return
case streamCh <- log:
}
case <-d.doneCh:
d.Lock()
defer d.Unlock()

d.logger.DeregisterSink(d.sink)
close(d.logCh)
return
}
}
}()

// run a go routine that periodically checks for
// dropped messages and makes room on the logCh
// to add a dropped message count warning
go func() {
// loop and check for dropped messages
LOOP:
Expand Down

0 comments on commit 8ccb770

Please sign in to comment.