From 51796165cf44e30ece4281c8353cbe25dae95d9f Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 2 Jul 2019 17:24:54 -0400 Subject: [PATCH] Move cmd.Wait() and put scanner in a go routine --- chatIn.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/chatIn.go b/chatIn.go index ab57f4b..5ef70ac 100644 --- a/chatIn.go +++ b/chatIn.go @@ -156,14 +156,16 @@ func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) { keybaseListen := exec.Command(k.Path, execCommand...) keybaseOutput, _ := keybaseListen.StdoutPipe() keybaseListen.Start() - keybaseListen.Wait() scanner := bufio.NewScanner(keybaseOutput) - var jsonData ChatIn - for scanner.Scan() { - json.Unmarshal([]byte(scanner.Text()), &jsonData) - c <- jsonData - } + 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