sort decorators before starting b.serve
Vladimir Bauer
1 year, 10 months ago
| 551 | 551 |
return table
|
| 552 | 552 |
}
|
| 553 | 553 |
|
|
554 |
func (s *bState) sortDecorators() {
|
|
555 |
for _, decorators := range s.decorators {
|
|
556 |
for _, d := range decorators {
|
|
557 |
d := unwrap(d)
|
|
558 |
if d, ok := d.(decor.AverageDecorator); ok {
|
|
559 |
s.averageDecorators = append(s.averageDecorators, d)
|
|
560 |
}
|
|
561 |
if d, ok := d.(decor.EwmaDecorator); ok {
|
|
562 |
s.ewmaDecorators = append(s.ewmaDecorators, d)
|
|
563 |
}
|
|
564 |
if d, ok := d.(decor.ShutdownListener); ok {
|
|
565 |
s.shutdownListeners = append(s.shutdownListeners, d)
|
|
566 |
}
|
|
567 |
}
|
|
568 |
}
|
|
569 |
}
|
|
570 |
|
| 554 | 571 |
func (s *bState) triggerCompletion(b *Bar) {
|
| 555 | 572 |
s.triggerComplete = true
|
| 556 | 573 |
if s.autoRefresh {
|
| 10 | 10 |
"time"
|
| 11 | 11 |
|
| 12 | 12 |
"github.com/vbauerster/mpb/v8/cwriter"
|
| 13 | |
"github.com/vbauerster/mpb/v8/decor"
|
| 14 | 13 |
)
|
| 15 | 14 |
|
| 16 | 15 |
const defaultRefreshRate = 150 * time.Millisecond
|
|
| 152 | 151 |
case p.operateState <- func(ps *pState) {
|
| 153 | 152 |
bs := ps.makeBarState(total, filler, options...)
|
| 154 | 153 |
bar := newBar(ps.ctx, p, bs)
|
| 155 | |
bar.TraverseDecorators(func(d decor.Decorator) {
|
| 156 | |
if d, ok := d.(decor.AverageDecorator); ok {
|
| 157 | |
bs.averageDecorators = append(bs.averageDecorators, d)
|
| 158 | |
}
|
| 159 | |
if d, ok := d.(decor.EwmaDecorator); ok {
|
| 160 | |
bs.ewmaDecorators = append(bs.ewmaDecorators, d)
|
| 161 | |
}
|
| 162 | |
if d, ok := d.(decor.ShutdownListener); ok {
|
| 163 | |
bs.shutdownListeners = append(bs.shutdownListeners, d)
|
| 164 | |
}
|
| 165 | |
})
|
| 166 | 154 |
if bs.waitBar != nil {
|
| 167 | 155 |
ps.queueBars[bs.waitBar] = bar
|
| 168 | 156 |
} else {
|
|
| 462 | 450 |
bs.buffers[1] = bytes.NewBuffer(make([]byte, 0, 128)) // append
|
| 463 | 451 |
bs.buffers[2] = bytes.NewBuffer(make([]byte, 0, 256)) // filler
|
| 464 | 452 |
|
|
453 |
bs.sortDecorators()
|
|
454 |
|
| 465 | 455 |
return bs
|
| 466 | 456 |
}
|