Skip to content

Commit

Permalink
Centralized the lineCallbackWaitGroup to the line scanner go-routine
Browse files Browse the repository at this point in the history
  • Loading branch information
keithpitt committed Nov 28, 2016
1 parent 42bf548 commit b9040fc
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func (p *Process) Start() error {
p.command.Env = append(currentEnv, p.Env...)

var waitGroup sync.WaitGroup
var lineCallbackWaitGroup sync.WaitGroup

lineReaderPipe, lineWriterPipe := io.Pipe()

Expand Down Expand Up @@ -128,6 +127,7 @@ func (p *Process) Start() error {
reader := bufio.NewReader(lineReaderPipe)

var appending []byte
var lineCallbackWaitGroup sync.WaitGroup

for {
line, isPrefix, err := reader.ReadLine()
Expand Down Expand Up @@ -174,8 +174,12 @@ func (p *Process) Start() error {
}(string(line))
}

logger.Debug("[LineScanner] Finished")
// We need to make sure all the line callbacks have finish before
// finish up the process
logger.Debug("[LineScanner] Waiting for callbacks to finish")
lineCallbackWaitGroup.Wait()

logger.Debug("[LineScanner] Finished")
waitGroup.Done()
}()

Expand Down Expand Up @@ -205,11 +209,6 @@ func (p *Process) Start() error {
logger.Debug("[Process] Timed out waiting for wait group: (%T: %v)", err, err)
}

// We need to make sure all the line callbacks have finish before
// finish up the process
logger.Debug("[Process] Waiting for line callbacks to finish")
lineCallbackWaitGroup.Wait()

// No error occurred so we can return nil
return nil
}
Expand Down

0 comments on commit b9040fc

Please sign in to comment.