rename param to iterDur
so it's clear what kind of duration it is.
Vladimir Bauer
3 years ago
| 238 | 238 | |
| 239 | 239 | // EwmaSetCurrent sets progress' current to an arbitrary value and updates |
| 240 | 240 | // EWMA based decorators by dur of a single iteration. |
| 241 | func (b *Bar) EwmaSetCurrent(current int64, dur time.Duration) { | |
| 241 | func (b *Bar) EwmaSetCurrent(current int64, iterDur time.Duration) { | |
| 242 | 242 | if current < 0 { |
| 243 | 243 | return |
| 244 | 244 | } |
| 245 | 245 | select { |
| 246 | 246 | case b.operateState <- func(s *bState) { |
| 247 | 247 | if n := current - s.current; n > 0 { |
| 248 | s.ewmaUpdate(n, dur) | |
| 248 | s.ewmaUpdate(n, iterDur) | |
| 249 | 249 | } |
| 250 | 250 | s.current = current |
| 251 | 251 | if s.triggerComplete && s.current >= s.total { |
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | // EwmaIncrement is a shorthand for b.EwmaIncrInt64(1, dur). | |
| 290 | func (b *Bar) EwmaIncrement(dur time.Duration) { | |
| 291 | b.EwmaIncrInt64(1, dur) | |
| 292 | } | |
| 293 | ||
| 294 | // EwmaIncrBy is a shorthand for b.EwmaIncrInt64(int64(n), dur). | |
| 295 | func (b *Bar) EwmaIncrBy(n int, dur time.Duration) { | |
| 296 | b.EwmaIncrInt64(int64(n), dur) | |
| 289 | // EwmaIncrement is a shorthand for b.EwmaIncrInt64(1, iterDur). | |
| 290 | func (b *Bar) EwmaIncrement(iterDur time.Duration) { | |
| 291 | b.EwmaIncrInt64(1, iterDur) | |
| 292 | } | |
| 293 | ||
| 294 | // EwmaIncrBy is a shorthand for b.EwmaIncrInt64(int64(n), iterDur). | |
| 295 | func (b *Bar) EwmaIncrBy(n int, iterDur time.Duration) { | |
| 296 | b.EwmaIncrInt64(int64(n), iterDur) | |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // EwmaIncrInt64 increments progress by amount of n and updates EWMA based |
| 300 | 300 | // decorators by dur of a single iteration. |
| 301 | func (b *Bar) EwmaIncrInt64(n int64, dur time.Duration) { | |
| 301 | func (b *Bar) EwmaIncrInt64(n int64, iterDur time.Duration) { | |
| 302 | 302 | if n <= 0 { |
| 303 | 303 | return |
| 304 | 304 | } |
| 305 | 305 | select { |
| 306 | 306 | case b.operateState <- func(s *bState) { |
| 307 | s.ewmaUpdate(n, dur) | |
| 307 | s.ewmaUpdate(n, iterDur) | |
| 308 | 308 | s.current += n |
| 309 | 309 | if s.triggerComplete && s.current >= s.total { |
| 310 | 310 | s.current = s.total |