diff --git a/bar.go b/bar.go index a5a8e4b..9472f5a 100644 --- a/bar.go +++ b/bar.go @@ -148,24 +148,23 @@ } } -// SetTotal sets total dynamically. -// If total is negative it takes progress' current value. -func (b *Bar) SetTotal(total int64, triggerComplete bool) { - select { - case b.operateState <- func(s *bState) { - s.triggerComplete = triggerComplete +// SetTotal sets total to an arbitrary value. Setting it to negative +// value is equivalent to (*Bar).SetTotal((*Bar).Current(), bool). +func (b *Bar) SetTotal(total int64, triggerCompleteNow bool) { + select { + case b.operateState <- func(s *bState) { if total < 0 { s.total = s.current } else { s.total = total } - if s.triggerComplete && !s.completed && !s.aborted { + if triggerCompleteNow { s.current = s.total s.completed = true go b.forceRefresh() } }: - if triggerComplete { + if triggerCompleteNow { <-b.done } case <-b.done: