Codebase list golang-github-vbauerster-mpb / ea00e62
refactoring: frame struct Vladimir Bauer 4 years ago
2 changed file(s) with 21 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
1919 priority int // used by heap
2020 index int // used by heap
2121
22 extendedLines int
2322 toShutdown bool
2423 toDrop bool
2524 noPop bool
2625 hasEwmaDecorators bool
2726 operateState chan func(*bState)
28 frameCh chan io.Reader
27 frameCh chan *frame
2928 syncTableCh chan [][]chan int
3029 completed chan bool
3130
7675 debugOut io.Writer
7776 }
7877
78 type frame struct {
79 reader io.Reader
80 lines int
81 }
82
7983 func newBar(container *Progress, bs *bState) *Bar {
8084 logPrefix := fmt.Sprintf("%sbar#%02d ", container.dlogger.Prefix(), bs.id)
8185 ctx, cancel := context.WithCancel(container.ctx)
8690 toDrop: bs.dropOnComplete,
8791 noPop: bs.noPop,
8892 operateState: make(chan func(*bState)),
89 frameCh: make(chan io.Reader, 1),
93 frameCh: make(chan *frame, 1),
9094 syncTableCh: make(chan [][]chan int, 1),
9195 completed: make(chan bool, 1),
9296 done: make(chan struct{}),
318322 b.toShutdown = !b.toShutdown
319323 b.recoveredPanic = p
320324 }
321 frame, lines := s.extender(nil, s.reqWidth, stat)
322 b.extendedLines = lines
323 b.frameCh <- frame
325 reader, lines := s.extender(nil, s.reqWidth, stat)
326 b.frameCh <- &frame{reader, lines}
324327 b.dlogger.Println(p)
325328 }
326329 s.completeFlushed = s.completed
327330 }()
328 frame, lines := s.extender(s.draw(stat), s.reqWidth, stat)
329 b.extendedLines = lines
331 reader, lines := s.extender(s.draw(stat), s.reqWidth, stat)
330332 b.toShutdown = s.completed && !s.completeFlushed
331 b.frameCh <- frame
333 b.frameCh <- &frame{reader, lines + 1}
332334 }:
333335 case <-b.done:
334336 s := b.cacheState
337339 if b.recoveredPanic == nil {
338340 r = s.draw(stat)
339341 }
340 frame, lines := s.extender(r, s.reqWidth, stat)
341 b.extendedLines = lines
342 b.frameCh <- frame
342 reader, lines := s.extender(r, s.reqWidth, stat)
343 b.frameCh <- &frame{reader, lines + 1}
343344 }
344345 }
345346
290290 }
291291
292292 func (s *pState) flush(cw *cwriter.Writer) error {
293 var lineCount int
294 bm := make(map[*Bar]struct{}, s.bHeap.Len())
293 var totalLines int
294 bm := make(map[*Bar]int, s.bHeap.Len())
295295 for s.bHeap.Len() > 0 {
296296 b := heap.Pop(&s.bHeap).(*Bar)
297 cw.ReadFrom(<-b.frameCh)
297 frame := <-b.frameCh
298 cw.ReadFrom(frame.reader)
298299 if b.toShutdown {
299300 if b.recoveredPanic != nil {
300301 s.barShutdownQueue = append(s.barShutdownQueue, b)
307308 }()
308309 }
309310 }
310 lineCount += b.extendedLines + 1
311 bm[b] = struct{}{}
311 bm[b] = frame.lines
312 totalLines += frame.lines
312313 }
313314
314315 for _, b := range s.barShutdownQueue {
319320 b.toDrop = true
320321 }
321322 if s.popCompleted && !b.noPop {
322 lineCount -= b.extendedLines + 1
323 totalLines -= bm[b]
323324 b.toDrop = true
324325 }
325326 if b.toDrop {
334335 heap.Push(&s.bHeap, b)
335336 }
336337
337 return cw.Flush(lineCount)
338 return cw.Flush(totalLines)
338339 }
339340
340341 func (s *pState) updateSyncMatrix() {