Update remove example
Vladimir Bauer
8 years ago
| 23 | 23 | for i := 0; i < numBars; i++ { |
| 24 | 24 | var name string |
| 25 | 25 | name = fmt.Sprintf("Bar#%d:", i) |
| 26 | ||
| 27 | var bOption mpb.BarOption | |
| 28 | if i == 0 { | |
| 29 | bOption = mpb.BarRemoveOnComplete() | |
| 30 | } | |
| 31 | ||
| 26 | 32 | b := p.AddBar(int64(total), mpb.BarID(i), |
| 27 | 33 | mpb.PrependDecorators( |
| 28 | 34 | decor.StaticName(name, 0, decor.DwidthSync|decor.DidentRight), |
| 31 | 37 | mpb.AppendDecorators( |
| 32 | 38 | decor.Percentage(5, 0), |
| 33 | 39 | ), |
| 40 | bOption, | |
| 34 | 41 | ) |
| 35 | 42 | go func() { |
| 36 | 43 | defer wg.Done() |
| 37 | 44 | max := 100 * time.Millisecond |
| 38 | 45 | for i := 0; i < total; i++ { |
| 39 | if b.ID() == 1 && i == 42 { | |
| 40 | p.RemoveBar(b) | |
| 46 | if b.ID() == 2 && i == 42 { | |
| 47 | p.Abort(b) | |
| 41 | 48 | return |
| 42 | 49 | } |
| 43 | 50 | time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) |
| 44 | 51 | b.Increment() |
| 45 | } | |
| 46 | if b.ID() == 0 { | |
| 47 | p.RemoveBar(b) | |
| 48 | 52 | } |
| 49 | 53 | }() |
| 50 | 54 | } |