Codebase list golang-github-vbauerster-mpb / 06164b2
EwmaSetCurrent Vladimir Bauer 3 years ago
1 changed file(s) with 22 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
236236 }
237237 }
238238
239 // EwmaSetCurrent sets progress' current to an arbitrary value and updates
240 // EWMA based decorators by dur of a single iteration.
241 func (b *Bar) EwmaSetCurrent(current int64, dur time.Duration) {
242 if current < 0 {
243 return
244 }
245 select {
246 case b.operateState <- func(s *bState) {
247 if n := current - s.current; n > 0 {
248 s.ewmaUpdate(n, dur)
249 }
250 s.current = current
251 if s.triggerComplete && s.current >= s.total {
252 s.current = s.total
253 s.completed = true
254 go b.forceRefresh(s.manualRefresh)
255 }
256 }:
257 case <-b.done:
258 }
259 }
260
239261 // Increment is a shorthand for b.IncrInt64(1).
240262 func (b *Bar) Increment() {
241263 b.IncrInt64(1)