Unverified Commit a72bd5cf authored by Drew Bailey's avatar Drew Bailey
Browse files

use channel instead of empty string to determine close

parent 9bb606a0
Showing with 7 additions and 8 deletions
+7 -8
......@@ -255,26 +255,25 @@ func (a *Agent) Monitor(stopCh <-chan struct{}, q *QueryOptions) (chan string, e
logCh := make(chan string, 64)
go func() {
defer resp.Body.Close()
defer close(logCh)
scanner := bufio.NewScanner(resp.Body)
LOOP:
for {
select {
case <-stopCh:
return
default:
}
if scanner.Scan() {
// An empty string signals to the caller that
// the scan is done, so make sure we only emit
// that when the scanner says it's done, not if
// we happen to ingest an empty line.
if text := scanner.Text(); text != "" {
logCh <- text
} else {
logCh <- " "
}
} else {
logCh <- ""
break LOOP
}
}
}()
......
......@@ -101,8 +101,8 @@ func (c *MonitorCommand) Run(args []string) int {
OUTER:
for {
select {
case log := <-logCh:
if log == "" {
case log, ok := <-logCh:
if !ok {
break OUTER
}
c.Ui.Output(log)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment