Browse Source

Put cmd.Start() and cmd.Wait() in a loop so keybase restarts if it dies

main
Sam 6 years ago
parent
commit
354fa145e1
  1. 22
      chatIn.go

22
chatIn.go

@ -155,17 +155,19 @@ func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) {
} }
keybaseListen := exec.Command(k.Path, execCommand...) keybaseListen := exec.Command(k.Path, execCommand...)
keybaseOutput, _ := keybaseListen.StdoutPipe() keybaseOutput, _ := keybaseListen.StdoutPipe()
keybaseListen.Start()
scanner := bufio.NewScanner(keybaseOutput)
go func(scanner *bufio.Scanner, c chan<- ChatIn) { for {
var jsonData ChatIn keybaseListen.Start()
for scanner.Scan() { scanner := bufio.NewScanner(keybaseOutput)
json.Unmarshal([]byte(scanner.Text()), &jsonData) go func(scanner *bufio.Scanner, c chan<- ChatIn) {
c <- jsonData var jsonData ChatIn
} for scanner.Scan() {
}(scanner, c) json.Unmarshal([]byte(scanner.Text()), &jsonData)
keybaseListen.Wait() c <- jsonData
}
}(scanner, c)
keybaseListen.Wait()
}
} }
// Run() runs keybase chat api-listen, and passes incoming messages to the message handler func // Run() runs keybase chat api-listen, and passes incoming messages to the message handler func

Loading…
Cancel
Save