Read only if there is something to read

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
David Gageot 2015-12-28 11:32:31 +01:00
parent 232c0ea37e
commit 501c4f3460
1 changed files with 6 additions and 5 deletions

View File

@ -173,12 +173,13 @@ func stream(scanner *bufio.Scanner, streamOutCh chan<- string, stopCh <-chan boo
close(streamOutCh)
return
default:
scanner.Scan()
line := scanner.Text()
if err := scanner.Err(); err != nil {
log.Warnf("Scanning stream: %s", err)
if scanner.Scan() {
line := scanner.Text()
if err := scanner.Err(); err != nil {
log.Warnf("Scanning stream: %s", err)
}
streamOutCh <- strings.Trim(line, "\n")
}
streamOutCh <- strings.Trim(line, "\n")
}
}
}