From 354fa145e16ae6d61fe95acfd3712f3c0599fdd5 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 2 Jul 2019 21:09:37 -0400 Subject: [PATCH] Put cmd.Start() and cmd.Wait() in a loop so keybase restarts if it dies --- chatIn.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/chatIn.go b/chatIn.go index 5ef70ac..ba0150e 100644 --- a/chatIn.go +++ b/chatIn.go @@ -155,17 +155,19 @@ func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) { } keybaseListen := exec.Command(k.Path, execCommand...) keybaseOutput, _ := keybaseListen.StdoutPipe() - keybaseListen.Start() - scanner := bufio.NewScanner(keybaseOutput) - go func(scanner *bufio.Scanner, c chan<- ChatIn) { - var jsonData ChatIn - for scanner.Scan() { - json.Unmarshal([]byte(scanner.Text()), &jsonData) - c <- jsonData - } - }(scanner, c) - keybaseListen.Wait() + for { + keybaseListen.Start() + scanner := bufio.NewScanner(keybaseOutput) + go func(scanner *bufio.Scanner, c chan<- ChatIn) { + var jsonData ChatIn + for scanner.Scan() { + json.Unmarshal([]byte(scanner.Text()), &jsonData) + c <- jsonData + } + }(scanner, c) + keybaseListen.Wait() + } } // Run() runs keybase chat api-listen, and passes incoming messages to the message handler func