Codebase list golang-github-vbauerster-mpb / d8400e9
refactoring barExtenderRev minor changes and some comment Vladimir Bauer 3 years ago
1 changed file(s) with 10 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
4242
4343 for i := 0; i < numTasks; i++ {
4444 bar := p.AddBar(tasks[i].total,
45 mpb.BarExtender(filler, true),
45 mpb.BarExtender(filler, true), // all bars share same extender filler
4646 mpb.BarFuncOptional(func() mpb.BarOption {
4747 return mpb.BarQueueAfter(tasks[i-1].bar)
4848 }, i != 0),
7171
7272 for _, t := range tasks {
7373 atomic.StoreUint32(&curTask, t.id)
74 complete(tb, t)
74 complete(t.bar, tb)
7575 atomic.AddUint32(&doneTasks, 1)
7676 }
7777
119119 })
120120 }
121121
122 func complete(tb *mpb.Bar, t *task) {
123 bar := t.bar
122 func complete(bar, totalBar *mpb.Bar) {
124123 max := 100 * time.Millisecond
125124 for !bar.Completed() {
126125 n := rand.Int63n(10) + 1
127 bar.IncrInt64(n)
128 go tb.IncrInt64(n)
126 incrementBars(n, bar, totalBar)
129127 time.Sleep(time.Duration(n) * max / 10)
130128 }
131129 bar.Wait()
132130 }
131
132 func incrementBars(n int64, bb ...*mpb.Bar) {
133 for _, b := range bb {
134 b.IncrInt64(n)
135 }
136 }