diff --git a/_examples/complex/main.go b/_examples/complex/main.go index 315d5f3..738cde7 100644 --- a/_examples/complex/main.go +++ b/_examples/complex/main.go @@ -28,7 +28,6 @@ task := fmt.Sprintf("Task#%02d:", i) job := "downloading" b := p.AddBar(rand.Int63n(201)+100, - mpb.BarRemoveOnComplete(), mpb.PrependDecorators( decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}), decor.Name(job, decor.WCSyncSpaceR), diff --git a/bar.go b/bar.go index 3cafb07..4213a7b 100644 --- a/bar.go +++ b/bar.go @@ -35,13 +35,13 @@ priority int // used by heap index int // used by heap - extendedLines int - toShutdown bool - dropOnComplete bool - operateState chan func(*bState) - frameCh chan io.Reader - syncTableCh chan [][]chan int - completed chan bool + extendedLines int + toShutdown bool + toDrop bool + operateState chan func(*bState) + frameCh chan io.Reader + syncTableCh chan [][]chan int + completed chan bool // concel is called either by user or on complete event cancel func() @@ -100,16 +100,16 @@ logPrefix := fmt.Sprintf("%sbar#%02d ", container.dlogger.Prefix(), bs.id) ctx, cancel := context.WithCancel(container.ctx) bar := &Bar{ - container: container, - priority: bs.priority, - dropOnComplete: bs.dropOnComplete, - operateState: make(chan func(*bState)), - frameCh: make(chan io.Reader, 1), - syncTableCh: make(chan [][]chan int), - completed: make(chan bool, 1), - done: make(chan struct{}), - cancel: cancel, - dlogger: log.New(bs.debugOut, logPrefix, log.Lshortfile), + container: container, + priority: bs.priority, + toDrop: bs.dropOnComplete, + operateState: make(chan func(*bState)), + frameCh: make(chan io.Reader, 1), + syncTableCh: make(chan [][]chan int), + completed: make(chan bool, 1), + done: make(chan struct{}), + cancel: cancel, + dlogger: log.New(bs.debugOut, logPrefix, log.Lshortfile), } go bar.serve(ctx, bs) @@ -316,6 +316,7 @@ frame = io.MultiReader(frame, s.bufE) } + b.toDrop = s.dropOnComplete b.toShutdown = s.toComplete && !s.completeFlushed s.completeFlushed = s.toComplete @@ -409,6 +410,13 @@ } } +func (b *Bar) dropOnComplete() { + select { + case b.operateState <- func(s *bState) { s.dropOnComplete = true }: + case <-b.done: + } +} + func newStatistics(s *bState) *decor.Statistics { return &decor.Statistics{ ID: s.id, diff --git a/bar_option.go b/bar_option.go index 7864e27..28dc7f2 100644 --- a/bar_option.go +++ b/bar_option.go @@ -67,10 +67,10 @@ // BarParkTo parks constructed bar into the runningBar. In other words, // constructed bar will start only after runningBar has been completed. -// Parked bar will replace runningBar if BarRemoveOnComplete option -// is set on the runningBar. Parked bar inherits priority of the -// runningBar, if no BarPriority option is set. +// Parked bar inherits priority of the runningBar, if no BarPriority +// option is set. Parked bar will replace runningBar eventually. func BarParkTo(runningBar *Bar) BarOption { + runningBar.dropOnComplete() return func(s *bState) { s.runningBar = runningBar } diff --git a/progress.go b/progress.go index fbd5f2d..e3d5e39 100644 --- a/progress.go +++ b/progress.go @@ -270,7 +270,7 @@ s.heapUpdated = true delete(s.parkedBars, bar) } - if bar.dropOnComplete { + if bar.toDrop { s.heapUpdated = true return }