Codebase list golang-github-vbauerster-mpb / 4af5641
setting total to 0 never completes Vladimir Bauer 7 years ago
2 changed file(s) with 6 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
169169 }
170170
171171 // SetTotal sets total dynamically.
172 // Set final to true, when total is known, it will trigger bar complete event.
173 func (b *Bar) SetTotal(total int64, final bool) bool {
172 // Set toComplete to true, to trigger bar complete event now.
173 func (b *Bar) SetTotal(total int64, toComplete bool) {
174174 select {
175175 case b.operateState <- func(s *bState) {
176 if total > 0 {
177 s.total = total
178 }
179 if final && !s.toComplete {
176 s.total = total
177 if toComplete && !s.toComplete {
180178 s.current = s.total
181179 s.toComplete = true
182180 go b.refreshNowTillShutdown()
183181 }
184182 }:
185 return true
186 case <-b.done:
187 return false
183 case <-b.done:
188184 }
189185 }
190186
212208 select {
213209 case b.operateState <- func(s *bState) {
214210 s.current += int64(n)
215 if s.current >= s.total && !s.toComplete {
211 if s.total > 0 && s.current >= s.total {
216212 s.current = s.total
217213 s.toComplete = true
218214 go b.refreshNowTillShutdown()
110110
111111 // Add creates a bar which renders itself by provided filler.
112112 func (p *Progress) Add(total int64, filler Filler, options ...BarOption) *Bar {
113 if total <= 0 {
114 total = time.Now().Unix()
115 }
116113 if filler == nil {
117114 filler = newDefaultBarFiller()
118115 }