Codebase list golang-github-vbauerster-mpb / e16a947
UpdateBarPriority: avoid indirection Vladimir Bauer 4 years ago
2 changed file(s) with 11 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
260260 // priority, i.e. bar will be on top. If you don't need to set priority
261261 // dynamically, better use BarPriority option.
262262 func (b *Bar) SetPriority(priority int) {
263 b.container.setBarPriority(b, priority)
263 b.container.UpdateBarPriority(b, priority)
264264 }
265265
266266 // Abort interrupts bar's running goroutine. Abort won't be engaged
156156 }
157157 }
158158
159 func (p *Progress) setBarPriority(b *Bar, priority int) {
160 select {
161 case p.operateState <- func(s *pState) {
162 if b.index < 0 {
163 return
164 }
165 b.priority = priority
166 heap.Fix(&s.bHeap, b.index)
167 }:
168 case <-p.done:
169 }
170 }
171
172159 func (p *Progress) traverseBars(cb func(b *Bar) bool) {
173160 done := make(chan struct{})
174161 select {
188175
189176 // UpdateBarPriority same as *Bar.SetPriority(int).
190177 func (p *Progress) UpdateBarPriority(b *Bar, priority int) {
191 p.setBarPriority(b, priority)
178 select {
179 case p.operateState <- func(s *pState) {
180 if b.index < 0 {
181 return
182 }
183 b.priority = priority
184 heap.Fix(&s.bHeap, b.index)
185 }:
186 case <-p.done:
187 }
192188 }
193189
194190 // BarCount returns bars count.