diff --git a/tea.go b/tea.go index f5f452b..0c29a86 100644 --- a/tea.go +++ b/tea.go @@ -474,11 +474,14 @@ func (p *Program) Run() (Model, error) { // Tear down. p.cancel() - // Wait for input loop to finish. - if p.cancelReader.Cancel() { - p.waitForReadLoop() + // Check if the cancel reader has been setup before waiting and closing. + if p.cancelReader != nil { + // Wait for input loop to finish. + if p.cancelReader.Cancel() { + p.waitForReadLoop() + } + _ = p.cancelReader.Close() } - _ = p.cancelReader.Close() // Wait for all handlers to finish. handlers.shutdown()