SetPriority
Vladimir Bauer
7 years ago
| 40 | 40 |
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
|
| 41 | 41 |
if i&1 == 1 {
|
| 42 | 42 |
priority := total - int(b.Current())
|
| 43 | |
p.UpdateBarPriority(b, priority)
|
|
43 |
b.SetPriority(priority)
|
| 44 | 44 |
}
|
| 45 | 45 |
// ewma based decorators require work duration measurement
|
| 46 | 46 |
b.IncrBy(1, time.Since(start))
|
| 227 | 227 |
}
|
| 228 | 228 |
}
|
| 229 | 229 |
|
| 230 | |
// SetOrder changes bar's order among multiple bars. Zero is highest
|
| 231 | |
// priority, i.e. bar will be on top. If you don't need to set order
|
|
230 |
// SetPriority changes bar's order among multiple bars. Zero is highest
|
|
231 |
// priority, i.e. bar will be on top. If you don't need to set priority
|
| 232 | 232 |
// dynamically, better use BarPriority option.
|
| 233 | |
func (b *Bar) SetOrder(order int) {
|
|
233 |
func (b *Bar) SetPriority(priority int) {
|
| 234 | 234 |
select {
|
| 235 | 235 |
case <-b.done:
|
| 236 | 236 |
default:
|
| 237 | |
b.container.setBarOrder(b, order)
|
|
237 |
b.container.setBarPriority(b, priority)
|
| 238 | 238 |
}
|
| 239 | 239 |
}
|
| 240 | 240 |
|
| 165 | 165 |
|
| 166 | 166 |
// UpdateBarPriority is deprecated. Please use *Bar.SetOrder.
|
| 167 | 167 |
func (p *Progress) UpdateBarPriority(b *Bar, priority int) {
|
| 168 | |
p.setBarOrder(b, priority)
|
| 169 | |
}
|
| 170 | |
|
| 171 | |
func (p *Progress) setBarOrder(b *Bar, order int) {
|
|
168 |
p.setBarPriority(b, priority)
|
|
169 |
}
|
|
170 |
|
|
171 |
func (p *Progress) setBarPriority(b *Bar, priority int) {
|
| 172 | 172 |
select {
|
| 173 | |
case p.operateState <- func(s *pState) { s.bHeap.update(b, order) }:
|
|
173 |
case p.operateState <- func(s *pState) { s.bHeap.update(b, priority) }:
|
| 174 | 174 |
case <-p.done:
|
| 175 | 175 |
}
|
| 176 | 176 |
}
|