diff --git a/src/core.go b/src/core.go index d9d98d1..c5ad235 100644 --- a/src/core.go +++ b/src/core.go @@ -139,7 +139,7 @@ func Run(opts *Options, revision string) { if !streamingFilter { reader = NewReader(func(data []byte) bool { return chunkList.Push(data) - }, eventBox, opts.ReadZero) + }, eventBox, opts.ReadZero, opts.Filter == nil) go reader.ReadSource() } @@ -183,7 +183,7 @@ func Run(opts *Options, revision string) { } } return false - }, eventBox, opts.ReadZero) + }, eventBox, opts.ReadZero, false) reader.ReadSource() } else { eventBox.Unwatch(EvtReadNew) diff --git a/src/reader.go b/src/reader.go index dd68486..b388411 100644 --- a/src/reader.go +++ b/src/reader.go @@ -23,11 +23,12 @@ type Reader struct { exec *exec.Cmd command *string killed bool + wait bool } // NewReader returns new Reader object -func NewReader(pusher func([]byte) bool, eventBox *util.EventBox, delimNil bool) *Reader { - return &Reader{pusher, eventBox, delimNil, int32(EvtReady), make(chan bool, 1), sync.Mutex{}, nil, nil, false} +func NewReader(pusher func([]byte) bool, eventBox *util.EventBox, delimNil bool, wait bool) *Reader { + return &Reader{pusher, eventBox, delimNil, int32(EvtReady), make(chan bool, 1), sync.Mutex{}, nil, nil, false, wait} } func (r *Reader) startEventPoller() { @@ -39,7 +40,9 @@ func (r *Reader) startEventPoller() { r.eventBox.Set(EvtReadNew, (*string)(nil)) pollInterval = readerPollIntervalMin } else if atomic.LoadInt32(ptr) == int32(EvtReadFin) { - r.finChan <- true + if r.wait { + r.finChan <- true + } return } else { pollInterval += readerPollIntervalStep @@ -54,7 +57,9 @@ func (r *Reader) startEventPoller() { func (r *Reader) fin(success bool) { atomic.StoreInt32(&r.event, int32(EvtReadFin)) - <-r.finChan + if r.wait { + <-r.finChan + } r.mutex.Lock() ret := r.command diff --git a/src/reader_test.go b/src/reader_test.go index b061068..8bbb488 100644 --- a/src/reader_test.go +++ b/src/reader_test.go @@ -10,11 +10,9 @@ import ( func TestReadFromCommand(t *testing.T) { strs := []string{} eb := util.NewEventBox() - reader := Reader{ - pusher: func(s []byte) bool { strs = append(strs, string(s)); return true }, - finChan: make(chan bool, 1), - eventBox: eb, - event: int32(EvtReady)} + reader := NewReader( + func(s []byte) bool { strs = append(strs, string(s)); return true }, + eb, false, true) reader.startEventPoller()