refactoring UpdateBarPriority
Vladimir Bauer
3 years ago
| 30 | 30 |
type pushData struct {
|
| 31 | 31 |
bar *Bar
|
| 32 | 32 |
sync bool
|
|
33 |
}
|
|
34 |
|
|
35 |
type fixData struct {
|
|
36 |
bar *Bar
|
|
37 |
priority int
|
| 33 | 38 |
}
|
| 34 | 39 |
|
| 35 | 40 |
func (m heapManager) run() {
|
|
| 87 | 92 |
}
|
| 88 | 93 |
close(data.iter)
|
| 89 | 94 |
case h_fix:
|
| 90 | |
heap.Fix(&bHeap, req.data.(int))
|
|
95 |
data := req.data.(fixData)
|
|
96 |
bar, priority := data.bar, data.priority
|
|
97 |
if bar.index < 0 {
|
|
98 |
break
|
|
99 |
}
|
|
100 |
bar.priority = priority
|
|
101 |
heap.Fix(&bHeap, bar.index)
|
| 91 | 102 |
case h_state:
|
| 92 | 103 |
ch := req.data.(chan<- bool)
|
| 93 | 104 |
ch <- sync || l != bHeap.Len()
|
|
| 122 | 133 |
m <- heapRequest{cmd: h_drain, data: data}
|
| 123 | 134 |
}
|
| 124 | 135 |
|
| 125 | |
func (m heapManager) fix(index int) {
|
| 126 | |
m <- heapRequest{cmd: h_push, data: index}
|
|
136 |
func (m heapManager) fix(b *Bar, priority int) {
|
|
137 |
data := fixData{b, priority}
|
|
138 |
m <- heapRequest{cmd: h_fix, data: data}
|
| 127 | 139 |
}
|
| 128 | 140 |
|
| 129 | 141 |
func (m heapManager) state(ch chan<- bool) {
|
| 178 | 178 |
// UpdateBarPriority same as *Bar.SetPriority(int).
|
| 179 | 179 |
func (p *Progress) UpdateBarPriority(b *Bar, priority int) {
|
| 180 | 180 |
select {
|
| 181 | |
case p.operateState <- func(s *pState) {
|
| 182 | |
if b.index < 0 {
|
| 183 | |
return
|
| 184 | |
}
|
| 185 | |
b.priority = priority
|
| 186 | |
s.hm.fix(b.index)
|
| 187 | |
}:
|
|
181 |
case p.operateState <- func(s *pState) { s.hm.fix(b, priority) }:
|
| 188 | 182 |
case <-p.done:
|
| 189 | 183 |
}
|
| 190 | 184 |
}
|