diff --git a/examples/remove/main.go b/examples/remove/main.go index 8aa145e..4e5d785 100644 --- a/examples/remove/main.go +++ b/examples/remove/main.go @@ -24,6 +24,12 @@ for i := 0; i < numBars; i++ { var name string name = fmt.Sprintf("Bar#%d:", i) + + var bOption mpb.BarOption + if i == 0 { + bOption = mpb.BarRemoveOnComplete() + } + b := p.AddBar(int64(total), mpb.BarID(i), mpb.PrependDecorators( decor.StaticName(name, 0, decor.DwidthSync|decor.DidentRight), @@ -32,20 +38,18 @@ mpb.AppendDecorators( decor.Percentage(5, 0), ), + bOption, ) go func() { defer wg.Done() max := 100 * time.Millisecond for i := 0; i < total; i++ { - if b.ID() == 1 && i == 42 { - p.RemoveBar(b) + if b.ID() == 2 && i == 42 { + p.Abort(b) return } time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) b.Increment() - } - if b.ID() == 0 { - p.RemoveBar(b) } }() }