Codebase list golang-github-vbauerster-mpb / 895ec23
refactoring flush frame.shutdown path Vladimir Bauer 2 years ago
1 changed file(s) with 27 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
356356
357357 func (s *pState) flush(cw *cwriter.Writer, height int) error {
358358 var wg sync.WaitGroup
359 defer wg.Wait() // waiting for all s.hm.push to complete
359 defer wg.Wait() // waiting for all s.push to complete
360360
361361 var popCount int
362362 var rows []io.Reader
380380 _, _ = io.Copy(io.Discard, row)
381381 }
382382 }
383 if frame.shutdown != 0 && !frame.done {
383
384 switch frame.shutdown {
385 case 1:
386 b.cancel()
384387 if qb, ok := s.queueBars[b]; ok {
385 b.cancel()
386388 delete(s.queueBars, b)
387389 qb.priority = b.priority
388390 wg.Add(1)
389 go func(b *Bar) {
390 s.hm.push(b, true)
391 wg.Done()
392 }(qb)
393 continue
394 }
391 go s.push(&wg, qb, true)
392 } else if s.popCompleted && !frame.noPop {
393 b.priority = s.popPriority
394 s.popPriority++
395 wg.Add(1)
396 go s.push(&wg, b, false)
397 } else if !frame.rmOnComplete {
398 wg.Add(1)
399 go s.push(&wg, b, false)
400 }
401 case 2:
395402 if s.popCompleted && !frame.noPop {
396 switch frame.shutdown {
397 case 1:
398 b.priority = s.popPriority
399 s.popPriority++
400 default:
401 b.cancel()
402 popCount += usedRows
403 continue
404 }
405 } else if frame.rmOnComplete {
406 b.cancel()
407 continue
408 } else {
409 b.cancel()
410 }
411 }
412 wg.Add(1)
413 go func(b *Bar) {
414 s.hm.push(b, false)
415 wg.Done()
416 }(b)
403 popCount += usedRows
404 }
405 default:
406 wg.Add(1)
407 go s.push(&wg, b, false)
408 }
417409 }
418410
419411 for i := len(rows) - 1; i >= 0; i-- {
424416 }
425417
426418 return cw.Flush(len(rows) - popCount)
419 }
420
421 func (s pState) push(wg *sync.WaitGroup, b *Bar, sync bool) {
422 s.hm.push(b, sync)
423 wg.Done()
427424 }
428425
429426 func (s pState) makeBarState(total int64, filler BarFiller, options ...BarOption) *bState {