Codebase list golang-github-vbauerster-mpb / db68229
put bar serve method back Vladimir Bauer 4 years ago
2 changed file(s) with 27 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
6868 complete bool
6969 }
7070
71 func newBar(container *Progress, bs *bState) (*Bar, func()) {
71 func newBar(container *Progress, bs *bState) *Bar {
7272 ctx, cancel := context.WithCancel(container.ctx)
73 operateState := make(chan func(*bState))
74 done := make(chan struct{})
75 serve := func() {
76 defer container.bwg.Done()
77 for {
78 select {
79 case op := <-operateState:
80 op(bs)
81 case <-ctx.Done():
82 bs.aborted = !bs.completed
83 bs.decoratorShutdownNotify()
84 close(done)
85 return
86 }
87 }
88 }
8973
9074 bar := &Bar{
9175 priority: bs.priority,
9276 hasEwma: len(bs.ewmaDecorators) != 0,
9377 frameCh: make(chan *frame, 1),
94 operateState: operateState,
95 done: done,
78 operateState: make(chan func(*bState)),
79 done: make(chan struct{}),
9680 container: container,
97 bs: bs,
9881 cancel: cancel,
9982 }
10083
101 return bar, serve
84 go bar.serve(ctx, bs)
85 return bar
10286 }
10387
10488 // ProxyReader wraps r with metrics required for progress tracking.
310294 return <-result
311295 case <-b.done:
312296 return b.bs.completed
297 }
298 }
299
300 func (b *Bar) serve(ctx context.Context, bs *bState) {
301 defer b.container.bwg.Done()
302 for {
303 select {
304 case op := <-b.operateState:
305 op(bs)
306 case <-ctx.Done():
307 bs.aborted = !bs.completed
308 bs.decoratorShutdownNotify()
309 b.bs = bs
310 close(b.done)
311 return
312 }
313313 }
314314 }
315315
4848 externalRefresh <-chan interface{}
4949 renderDelay <-chan struct{}
5050 shutdownNotifier chan struct{}
51 queueBars map[*Bar]queueBar
51 queueBars map[*Bar]*Bar
5252 output io.Writer
5353 debugOut io.Writer
54 }
55
56 type queueBar struct {
57 bar *Bar
58 serve func()
5954 }
6055
6156 // New creates new Progress container instance. It's not possible to
7166 s := &pState{
7267 bHeap: priorityQueue{},
7368 rr: prr,
74 queueBars: make(map[*Bar]queueBar),
69 queueBars: make(map[*Bar]*Bar),
7570 output: os.Stdout,
7671 }
7772
122117 select {
123118 case p.operateState <- func(ps *pState) {
124119 bs := ps.makeBarState(total, filler, options...)
125 bar, serve := newBar(p, bs)
120 bar := newBar(p, bs)
126121 if bs.afterBar != nil {
127 ps.queueBars[bs.afterBar] = queueBar{bar, serve}
122 ps.queueBars[bs.afterBar] = bar
128123 } else {
129124 heap.Push(&ps.bHeap, bar)
130125 ps.heapUpdated = true
131 go serve()
132126 }
133127 ps.idCount++
134128 result <- bar
292286 var toDrop bool
293287 if qb, ok := s.queueBars[b]; ok {
294288 delete(s.queueBars, b)
295 qb.bar.priority = b.priority
296 heap.Push(&s.bHeap, qb.bar)
297 go qb.serve()
289 qb.priority = b.priority
290 heap.Push(&s.bHeap, qb)
298291 toDrop = true
299292 } else if s.popCompleted && !b.bs.noPop {
300293 frame := bm[b]