Codebase list golang-github-vbauerster-mpb / 3541dba
set bar.hasEwma Vladimir Bauer 4 years ago
3 changed file(s) with 35 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
1616
1717 // Bar represents a progress bar.
1818 type Bar struct {
19 index int // used by heap
20 priority int // used by heap
21 hasEwmaDecorators bool
22 frameCh chan *frame
23 operateState chan func(*bState)
24 done chan struct{}
25 container *Progress
26 bs *bState
27 cancel func()
28 recoveredPanic interface{}
19 index int // used by heap
20 priority int // used by heap
21 hasEwma bool
22 frameCh chan *frame
23 operateState chan func(*bState)
24 done chan struct{}
25 container *Progress
26 bs *bState
27 cancel func()
28 recoveredPanic interface{}
2929 }
3030
3131 type extenderFunc func(in io.Reader, reqWidth int, st decor.Statistics) (out io.Reader, lines int)
8888
8989 bar := &Bar{
9090 priority: bs.priority,
91 hasEwma: len(bs.ewmaDecorators) != 0,
9192 frameCh: make(chan *frame, 1),
9293 operateState: operateState,
9394 done: done,
9596 bs: bs,
9697 cancel: cancel,
9798 }
98
99 bar.subscribeDecorators(bs)
10099
101100 return bar, serve
102101 }
348347 }
349348 }
350349
351 func (b *Bar) subscribeDecorators(bs *bState) {
352 for _, decorators := range [...][]decor.Decorator{
353 bs.pDecorators,
354 bs.aDecorators,
355 } {
356 for _, d := range decorators {
357 d = extractBaseDecorator(d)
358 if d, ok := d.(decor.AverageDecorator); ok {
359 bs.averageDecorators = append(bs.averageDecorators, d)
360 }
361 if d, ok := d.(decor.EwmaDecorator); ok {
362 bs.ewmaDecorators = append(bs.ewmaDecorators, d)
363 }
364 if d, ok := d.(decor.ShutdownListener); ok {
365 bs.shutdownListeners = append(bs.shutdownListeners, d)
366 }
367 }
368 }
369 }
370
371350 func (b *Bar) forceRefreshIfLastUncompleted() {
372351 var anyOtherUncompleted bool
373352 b.container.traverseBars(func(bar *Bar) bool {
456435 return table
457436 }
458437
438 func (s *bState) subscribeDecorators() {
439 for _, decorators := range [...][]decor.Decorator{
440 s.pDecorators,
441 s.aDecorators,
442 } {
443 for _, d := range decorators {
444 d = extractBaseDecorator(d)
445 if d, ok := d.(decor.AverageDecorator); ok {
446 s.averageDecorators = append(s.averageDecorators, d)
447 }
448 if d, ok := d.(decor.EwmaDecorator); ok {
449 s.ewmaDecorators = append(s.ewmaDecorators, d)
450 }
451 if d, ok := d.(decor.ShutdownListener); ok {
452 s.shutdownListeners = append(s.shutdownListeners, d)
453 }
454 }
455 }
456 }
457
459458 func (s bState) decoratorEwmaUpdate(dur time.Duration) {
460459 wg := new(sync.WaitGroup)
461460 for i := 0; i < len(s.ewmaDecorators); i++ {
405405 bs.buffers[i] = bytes.NewBuffer(make([]byte, 0, 512))
406406 }
407407
408 bs.subscribeDecorators()
409
408410 return bs
409411 }
410412
6464 pr := proxyReader{toReadCloser(r), b}
6565 if wt, ok := r.(io.WriterTo); ok {
6666 pw := proxyWriterTo{pr, wt}
67 if b.hasEwmaDecorators {
67 if b.hasEwma {
6868 rc = ewmaProxyWriterTo{ewmaProxyReader{pr}, pw}
6969 } else {
7070 rc = pw
7171 }
72 } else if b.hasEwmaDecorators {
72 } else if b.hasEwma {
7373 rc = ewmaProxyReader{pr}
7474 } else {
7575 rc = pr