Codebase list golang-github-vbauerster-mpb / 12a8d50
refactor SetTotal Vladimir Bauer 4 years ago
1 changed file(s) with 7 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
147147 }
148148 }
149149
150 // SetTotal sets total dynamically.
151 // If total is negative it takes progress' current value.
152 func (b *Bar) SetTotal(total int64, triggerComplete bool) {
153 select {
154 case b.operateState <- func(s *bState) {
155 s.triggerComplete = triggerComplete
150 // SetTotal sets total to an arbitrary value. Setting it to negative
151 // value is equivalent to (*Bar).SetTotal((*Bar).Current(), bool).
152 func (b *Bar) SetTotal(total int64, triggerCompleteNow bool) {
153 select {
154 case b.operateState <- func(s *bState) {
156155 if total < 0 {
157156 s.total = s.current
158157 } else {
159158 s.total = total
160159 }
161 if s.triggerComplete && !s.completed && !s.aborted {
160 if triggerCompleteNow {
162161 s.current = s.total
163162 s.completed = true
164163 go b.forceRefresh()
165164 }
166165 }:
167 if triggerComplete {
166 if triggerCompleteNow {
168167 <-b.done
169168 }
170169 case <-b.done: