UpdateBarPriority: avoid indirection
Vladimir Bauer
4 years ago
| 260 | 260 |
// priority, i.e. bar will be on top. If you don't need to set priority
|
| 261 | 261 |
// dynamically, better use BarPriority option.
|
| 262 | 262 |
func (b *Bar) SetPriority(priority int) {
|
| 263 | |
b.container.setBarPriority(b, priority)
|
|
263 |
b.container.UpdateBarPriority(b, priority)
|
| 264 | 264 |
}
|
| 265 | 265 |
|
| 266 | 266 |
// Abort interrupts bar's running goroutine. Abort won't be engaged
|
| 156 | 156 |
}
|
| 157 | 157 |
}
|
| 158 | 158 |
|
| 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 | |
|
| 172 | 159 |
func (p *Progress) traverseBars(cb func(b *Bar) bool) {
|
| 173 | 160 |
done := make(chan struct{})
|
| 174 | 161 |
select {
|
|
| 188 | 175 |
|
| 189 | 176 |
// UpdateBarPriority same as *Bar.SetPriority(int).
|
| 190 | 177 |
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 |
}
|
| 192 | 188 |
}
|
| 193 | 189 |
|
| 194 | 190 |
// BarCount returns bars count.
|