Codebase list golang-github-vbauerster-mpb / 32f1a4e
SetPriority Vladimir Bauer 7 years ago
3 changed file(s) with 10 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
4040 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4141 if i&1 == 1 {
4242 priority := total - int(b.Current())
43 p.UpdateBarPriority(b, priority)
43 b.SetPriority(priority)
4444 }
4545 // ewma based decorators require work duration measurement
4646 b.IncrBy(1, time.Since(start))
227227 }
228228 }
229229
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
232232 // dynamically, better use BarPriority option.
233 func (b *Bar) SetOrder(order int) {
233 func (b *Bar) SetPriority(priority int) {
234234 select {
235235 case <-b.done:
236236 default:
237 b.container.setBarOrder(b, order)
237 b.container.setBarPriority(b, priority)
238238 }
239239 }
240240
165165
166166 // UpdateBarPriority is deprecated. Please use *Bar.SetOrder.
167167 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) {
172172 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) }:
174174 case <-p.done:
175175 }
176176 }