diff --git a/bar.go b/bar.go index e815113..f6a319a 100644 --- a/bar.go +++ b/bar.go @@ -27,7 +27,7 @@ completeReqCh chan struct{} removeReqCh chan struct{} done chan struct{} - completed chan struct{} + inProgress chan struct{} cancel <-chan struct{} // follawing are used after (*Bar.done) is closed @@ -40,6 +40,7 @@ type Statistics struct { ID int Completed bool + Aborted bool Total int64 Current int64 StartTime time.Time @@ -73,6 +74,7 @@ trimLeftSpace bool trimRightSpace bool completed bool + aborted bool startTime time.Time timeElapsed time.Duration timePerItem time.Duration @@ -92,7 +94,7 @@ removeReqCh: make(chan struct{}), completeReqCh: make(chan struct{}), done: make(chan struct{}), - completed: make(chan struct{}), + inProgress: make(chan struct{}), cancel: conf.cancel, } @@ -237,7 +239,7 @@ // Can be used as condition in for loop func (b *Bar) InProgress() bool { select { - case <-b.completed: + case <-b.inProgress: return false default: return true @@ -324,7 +326,7 @@ s.updateTimePerItemEstimate(incrStartTime, r.amount) if n == s.total { s.completed = true - close(b.completed) + close(b.inProgress) } s.current = n if r.refill != nil { @@ -342,7 +344,8 @@ case <-b.removeReqCh: return case <-b.cancel: - close(b.completed) + s.aborted = true + close(b.inProgress) return } } @@ -492,6 +495,7 @@ return &Statistics{ ID: s.id, Completed: s.completed, + Aborted: s.aborted, Total: s.total, Current: s.current, StartTime: s.startTime, diff --git a/progress.go b/progress.go index af1ce66..f9d1c41 100644 --- a/progress.go +++ b/progress.go @@ -335,9 +335,9 @@ } case <-p.uncompletedBarStopReqCh: for _, b := range bars { - stat := b.GetStatistics() - if !stat.Completed { - b.Completed() + s := b.getState() + if !s.completed && !s.aborted { + b.Complete() } } case <-p.stopReqCh: