Codebase list golang-github-vbauerster-mpb / 6990696
refactoring UpdateBarPriority Vladimir Bauer 3 years ago
2 changed file(s) with 16 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
3030 type pushData struct {
3131 bar *Bar
3232 sync bool
33 }
34
35 type fixData struct {
36 bar *Bar
37 priority int
3338 }
3439
3540 func (m heapManager) run() {
8792 }
8893 close(data.iter)
8994 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)
91102 case h_state:
92103 ch := req.data.(chan<- bool)
93104 ch <- sync || l != bHeap.Len()
122133 m <- heapRequest{cmd: h_drain, data: data}
123134 }
124135
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}
127139 }
128140
129141 func (m heapManager) state(ch chan<- bool) {
178178 // UpdateBarPriority same as *Bar.SetPriority(int).
179179 func (p *Progress) UpdateBarPriority(b *Bar, priority int) {
180180 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) }:
188182 case <-p.done:
189183 }
190184 }