diff --git a/bar.go b/bar.go index 2dc35dc..e521868 100644 --- a/bar.go +++ b/bar.go @@ -237,6 +237,28 @@ } } +// EwmaSetCurrent sets progress' current to an arbitrary value and updates +// EWMA based decorators by dur of a single iteration. +func (b *Bar) EwmaSetCurrent(current int64, dur time.Duration) { + if current < 0 { + return + } + select { + case b.operateState <- func(s *bState) { + if n := current - s.current; n > 0 { + s.ewmaUpdate(n, dur) + } + s.current = current + if s.triggerComplete && s.current >= s.total { + s.current = s.total + s.completed = true + go b.forceRefresh(s.manualRefresh) + } + }: + case <-b.done: + } +} + // Increment is a shorthand for b.IncrInt64(1). func (b *Bar) Increment() { b.IncrInt64(1)