drop sync bool param of BarQueueAfter
Vladimir Bauer
3 years ago
| 44 | 44 |
bar := p.AddBar(tasks[i].total,
|
| 45 | 45 |
mpb.BarExtender(filler, true),
|
| 46 | 46 |
mpb.BarFuncOptional(func() mpb.BarOption {
|
| 47 | |
return mpb.BarQueueAfter(tasks[i-1].bar, false)
|
|
47 |
return mpb.BarQueueAfter(tasks[i-1].bar)
|
| 48 | 48 |
}, i != 0),
|
| 49 | 49 |
mpb.PrependDecorators(
|
| 50 | 50 |
decor.Name("current:", decor.WCSyncWidthR),
|
| 28 | 28 |
mpb.AppendDecorators(decor.Percentage(decor.WC{W: 5})),
|
| 29 | 29 |
)
|
| 30 | 30 |
queue[1] = p.AddBar(rand.Int63n(101)+100,
|
| 31 | |
mpb.BarQueueAfter(queue[0], false), // this bar is queued
|
|
31 |
mpb.BarQueueAfter(queue[0]), // this bar is queued
|
| 32 | 32 |
mpb.BarFillerClearOnComplete(),
|
| 33 | 33 |
mpb.PrependDecorators(
|
| 34 | 34 |
decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}),
|
| 51 | 51 |
filler BarFiller
|
| 52 | 52 |
extender extenderFunc
|
| 53 | 53 |
refreshCh chan time.Time
|
| 54 | |
|
| 55 | |
wait struct {
|
| 56 | |
bar *Bar // key for (*pState).queueBars
|
| 57 | |
sync bool
|
| 58 | |
}
|
|
54 |
waitBar *Bar // key for (*pState).queueBars
|
| 59 | 55 |
}
|
| 60 | 56 |
|
| 61 | 57 |
type renderFrame struct {
|
|
| 399 | 395 |
|
| 400 | 396 |
func (b *Bar) serve(ctx context.Context, bs *bState) {
|
| 401 | 397 |
defer b.container.bwg.Done()
|
| 402 | |
if bs.wait.bar != nil && bs.wait.sync {
|
| 403 | |
bs.wait.bar.Wait()
|
| 404 | |
}
|
| 405 | 398 |
for {
|
| 406 | 399 |
select {
|
| 407 | 400 |
case op := <-b.operateState:
|
| 58 | 58 |
// BarQueueAfter puts this (being constructed) bar into the queue.
|
| 59 | 59 |
// BarPriority will be inherited from the argument bar.
|
| 60 | 60 |
// When argument bar completes or aborts queued bar replaces its place.
|
| 61 | |
// If sync is true queued bar is suspended until argument bar completes
|
| 62 | |
// or aborts.
|
| 63 | |
func BarQueueAfter(bar *Bar, sync bool) BarOption {
|
| 64 | |
if bar == nil {
|
| 65 | |
return nil
|
| 66 | |
}
|
| 67 | |
return func(s *bState) {
|
| 68 | |
s.wait.bar = bar
|
| 69 | |
s.wait.sync = sync
|
|
61 |
func BarQueueAfter(bar *Bar) BarOption {
|
|
62 |
return func(s *bState) {
|
|
63 |
s.waitBar = bar
|
| 70 | 64 |
}
|
| 71 | 65 |
}
|
| 72 | 66 |
|
| 134 | 134 |
case p.operateState <- func(ps *pState) {
|
| 135 | 135 |
bs := ps.makeBarState(total, filler, options...)
|
| 136 | 136 |
bar := newBar(ps.ctx, p, bs)
|
| 137 | |
if bs.wait.bar != nil {
|
| 138 | |
ps.queueBars[bs.wait.bar] = bar
|
|
137 |
if bs.waitBar != nil {
|
|
138 |
ps.queueBars[bs.waitBar] = bar
|
| 139 | 139 |
} else {
|
| 140 | 140 |
ps.hm.push(bar, true)
|
| 141 | 141 |
}
|