Fix getting stuck when closing pager without reading all entries

This commit is contained in:
Jan Philipp Timme 2018-12-31 15:53:51 +01:00
parent 70420c456e
commit d39fb736dc
1 changed files with 7 additions and 2 deletions

View File

@ -55,9 +55,13 @@ func showQueue() {
reader, writer := io.Pipe()
pagerDone := make(chan bool)
go launchPager(reader, pagerDone)
// TODO: Figure out how to handle the pager closing before we're done writing
for _, entry := range entries {
fmt.Fprintf(writer, "%s\n", entry.String())
_, writeError := fmt.Fprintf(writer, "%s\n", entry.String())
if writeError != nil {
// A writeError is expected once the reader was closed
// This happens when the pager application got terminated
break
}
}
writer.Close()
// Wait for pager to be closed before continuing the main program
@ -74,6 +78,7 @@ func launchPager(reader *io.PipeReader, pagerDone chan<- bool) {
if err := cmd.Wait(); err != nil {
fmt.Printf("Error terminating pager: %s\n", err.Error())
} else {
reader.Close()
pagerDone <- true
}
}