summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authormjarkk <mkopenga@gmail.com>2018-11-03 09:36:38 +0100
committermjarkk <mkopenga@gmail.com>2018-11-03 09:36:38 +0100
commitcf1e9f79b1d1f7faad5c2ccff4536936b10f3e19 (patch)
treebf9160fba2eb15bc6e266a76f8e3a4e6fd828179 /pkg
parent8469239d84bc71bececc5a9027d3a3e0fe683fd6 (diff)
hopefully fixed the test now
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/exec_live_default.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/pkg/commands/exec_live_default.go b/pkg/commands/exec_live_default.go
index 88bbf2eb4..27363c3b9 100644
--- a/pkg/commands/exec_live_default.go
+++ b/pkg/commands/exec_live_default.go
@@ -20,7 +20,6 @@ import (
// NOTE: You don't have to include a enter in the return data this function will do that for you
func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) {
cmdOutput := []string{}
- canAsk := true
splitCmd := ToArgv(command)
cmd := exec.Command(splitCmd[0], splitCmd[1:]...)
@@ -34,6 +33,19 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
return errorMessage, err
}
+ var canAskLock sync.Mutex
+ canAskValue := true
+ canAsk := func() bool {
+ canAskLock.Lock()
+ defer canAskLock.Unlock()
+ return canAskValue
+ }
+ stopCanAsk := func() {
+ canAskLock.Lock()
+ defer canAskLock.Unlock()
+ canAskValue = false
+ }
+
var waitForBufio sync.WaitGroup
waitForBufio.Add(1)
@@ -50,7 +62,7 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
// canAsk prefrents calls to output when the program is already closed
- if canAsk {
+ if canAsk() {
toOutput := re.ReplaceAllString(scanner.Text(), "")
cmdOutput = append(cmdOutput, toOutput)
toWrite := output(toOutput)
@@ -63,9 +75,7 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
}()
if err := cmd.Wait(); err != nil {
- canAsk = false
-
- //
+ stopCanAsk()
waitForBufio.Wait()
return strings.Join(cmdOutput, " "), err
}