EwmaSetCurrent
Vladimir Bauer
3 years ago
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | 238 | |
| 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 | ||
| 239 | 261 | // Increment is a shorthand for b.IncrInt64(1). |
| 240 | 262 | func (b *Bar) Increment() { |
| 241 | 263 | b.IncrInt64(1) |