Codebase list golang-github-vbauerster-mpb / 6cc740c
sort decorators before starting b.serve Vladimir Bauer 1 year, 10 months ago
2 changed file(s) with 19 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
551551 return table
552552 }
553553
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
554571 func (s *bState) triggerCompletion(b *Bar) {
555572 s.triggerComplete = true
556573 if s.autoRefresh {
1010 "time"
1111
1212 "github.com/vbauerster/mpb/v8/cwriter"
13 "github.com/vbauerster/mpb/v8/decor"
1413 )
1514
1615 const defaultRefreshRate = 150 * time.Millisecond
152151 case p.operateState <- func(ps *pState) {
153152 bs := ps.makeBarState(total, filler, options...)
154153 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 })
166154 if bs.waitBar != nil {
167155 ps.queueBars[bs.waitBar] = bar
168156 } else {
462450 bs.buffers[1] = bytes.NewBuffer(make([]byte, 0, 128)) // append
463451 bs.buffers[2] = bytes.NewBuffer(make([]byte, 0, 256)) // filler
464452
453 bs.sortDecorators()
454
465455 return bs
466456 }