diff --git a/main.go b/main.go index 01c5145..aced510 100644 --- a/main.go +++ b/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 } }