diff --git a/heap_manager.go b/heap_manager.go index c8a2802..678dd7c 100644 --- a/heap_manager.go +++ b/heap_manager.go @@ -31,6 +31,11 @@ type pushData struct { bar *Bar sync bool +} + +type fixData struct { + bar *Bar + priority int } func (m heapManager) run() { @@ -88,7 +93,13 @@ } close(data.iter) case h_fix: - heap.Fix(&bHeap, req.data.(int)) + data := req.data.(fixData) + bar, priority := data.bar, data.priority + if bar.index < 0 { + break + } + bar.priority = priority + heap.Fix(&bHeap, bar.index) case h_state: ch := req.data.(chan<- bool) ch <- sync || l != bHeap.Len() @@ -123,8 +134,9 @@ m <- heapRequest{cmd: h_drain, data: data} } -func (m heapManager) fix(index int) { - m <- heapRequest{cmd: h_push, data: index} +func (m heapManager) fix(b *Bar, priority int) { + data := fixData{b, priority} + m <- heapRequest{cmd: h_fix, data: data} } func (m heapManager) state(ch chan<- bool) { diff --git a/progress.go b/progress.go index 447c322..d04b86e 100644 --- a/progress.go +++ b/progress.go @@ -179,13 +179,7 @@ // UpdateBarPriority same as *Bar.SetPriority(int). func (p *Progress) UpdateBarPriority(b *Bar, priority int) { select { - case p.operateState <- func(s *pState) { - if b.index < 0 { - return - } - b.priority = priority - s.hm.fix(b.index) - }: + case p.operateState <- func(s *pState) { s.hm.fix(b, priority) }: case <-p.done: } }