Codebase list golang-github-vbauerster-mpb / dfa2d5a
refactoring eta vars Vladimir Bauer 8 years ago
1 changed file(s) with 6 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
238238 if n < 1 {
239239 return
240240 }
241 now := time.Now()
241242 select {
242243 case b.operateState <- func(s *bState) {
243244 if s.toComplete {
244245 return
245246 }
246 next := time.Now()
247247 if s.current == 0 {
248 s.startTime = next
249 s.blockStartTime = next
248 s.startTime = now
249 s.blockStartTime = now
250250 } else {
251 now := time.Now()
252 s.updateTimePerItemEstimate(n, now, next)
251 s.updateTimePerItemEstimate(n, now)
253252 s.timeElapsed = now.Sub(s.startTime)
254253 }
255254 s.current += int64(n)
423422 }
424423 }
425424
426 func (s *bState) updateTimePerItemEstimate(amount int, now, next time.Time) {
425 func (s *bState) updateTimePerItemEstimate(amount int, now time.Time) {
427426 lastBlockTime := now.Sub(s.blockStartTime)
428427 lastItemEstimate := float64(lastBlockTime) / float64(amount)
429428 s.timePerItem = time.Duration((s.etaAlpha * lastItemEstimate) + (1-s.etaAlpha)*float64(s.timePerItem))
430 s.blockStartTime = next
429 s.blockStartTime = now
431430 }
432431
433432 func newStatistics(s *bState) *decor.Statistics {