Codebase list golang-github-vbauerster-mpb / d10d092
better ETA computation Vladimir Bauer 9 years ago
1 changed file(s) with 7 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
8080
8181 func newBar(id int, total int64, width int, format string, wg *sync.WaitGroup, cancel <-chan struct{}) *Bar {
8282 b := &Bar{
83 stateReqCh: make(chan chan state, 1),
83 stateReqCh: make(chan chan state),
8484 widthCh: make(chan int),
8585 formatCh: make(chan string),
8686 etaAlphaCh: make(chan float64),
254254 if isClosed(b.done) {
255255 return b.state
256256 }
257 ch := make(chan state, 1)
257 ch := make(chan state)
258258 b.stateReqCh <- ch
259259 return <-ch
260260 }
262262 func (b *Bar) server(id int, total int64, width int, format string, wg *sync.WaitGroup, cancel <-chan struct{}) {
263263 var completed bool
264264 timeStarted := time.Now()
265 blockStartTime := timeStarted
265 prevStartTime := timeStarted
266 var blockStartTime time.Time
266267 barState := state{
267268 id: id,
268269 width: width,
282283 for {
283284 select {
284285 case i := <-b.incrCh:
286 blockStartTime = time.Now()
285287 n := barState.current + i
286288 if total > 0 && n > total {
287289 barState.current = total
288290 completed = true
289 blockStartTime = time.Now()
290291 break // break out of select
291292 }
292293 barState.timeElapsed = time.Since(timeStarted)
293 barState.timePerItem = calcTimePerItemEstimate(barState.timePerItem, blockStartTime, barState.etaAlpha, i)
294 barState.timePerItem = calcTimePerItemEstimate(barState.timePerItem, prevStartTime, barState.etaAlpha, i)
294295 if n == total {
295296 completed = true
296297 }
297298 barState.current = n
298 blockStartTime = time.Now()
299 prevStartTime = blockStartTime
299300 case d := <-b.decoratorCh:
300301 switch d.kind {
301302 case decAppend: