Fix getting stuck when closing pager without reading all entries
This commit is contained in:
parent
70420c456e
commit
d39fb736dc
9
main.go
9
main.go
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue