Browse Source

Move cmd.Wait() and put scanner in a go routine

main
Sam 6 years ago
parent
commit
51796165cf
  1. 14
      chatIn.go

14
chatIn.go

@ -156,14 +156,16 @@ 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() keybaseListen.Start()
keybaseListen.Wait()
scanner := bufio.NewScanner(keybaseOutput) scanner := bufio.NewScanner(keybaseOutput)
var jsonData ChatIn
for scanner.Scan() { go func(scanner *bufio.Scanner, c chan<- ChatIn) {
json.Unmarshal([]byte(scanner.Text()), &jsonData) var jsonData ChatIn
c <- jsonData 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 // Run() runs keybase chat api-listen, and passes incoming messages to the message handler func

Loading…
Cancel
Save