Codebase list golang-github-vbauerster-mpb / aa04cc1
refactoring: barShutdownQueue Vladimir Bauer 7 years ago
1 changed file(s) with 18 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
3333 }
3434
3535 type pState struct {
36 bHeap *priorityQueue
37 shutdownPending []*Bar
38 heapUpdated bool
39 idCounter int
40 width int
41 rr time.Duration
42 pMatrix map[int][]chan int
43 aMatrix map[int][]chan int
44 output io.Writer
36 bHeap *priorityQueue
37 heapUpdated bool
38 pMatrix map[int][]chan int
39 aMatrix map[int][]chan int
40 barShutdownQueue []chan struct{}
4541
4642 // following are provided/overrided by user
43 idCount int
44 width int
45 rr time.Duration
4746 uwg *sync.WaitGroup
4847 manualRefreshCh <-chan time.Time
4948 shutdownNotifier chan struct{}
5049 parkedBars map[*Bar]*Bar
50 output io.Writer
5151 debugOut io.Writer
5252 }
5353
123123 bs := &bState{
124124 total: total,
125125 filler: filler,
126 priority: ps.idCounter,
127 id: ps.idCounter,
126 priority: ps.idCount,
127 id: ps.idCount,
128128 width: ps.width,
129129 }
130130 for _, opt := range options {
137137 prefix := fmt.Sprintf("%sbar#%02d ", p.dlogger.Prefix(), bs.id)
138138 bar.dlogger = log.New(ps.debugOut, prefix, log.Lshortfile)
139139 if bs.runningBar != nil {
140 if bar.priority == ps.idCounter {
140 if bar.priority == ps.idCount {
141141 bar.priority = bs.runningBar.priority
142142 }
143143 ps.parkedBars[bs.runningBar] = bar
145145 heap.Push(ps.bHeap, bar)
146146 ps.heapUpdated = true
147147 }
148 ps.idCounter++
148 ps.idCount++
149149 result <- bar
150150 }:
151151 return <-result
168168 if remove {
169169 s.heapUpdated = heap.Remove(s.bHeap, b.index) != nil
170170 }
171 s.shutdownPending = append(s.shutdownPending, b)
171 s.barShutdownQueue = append(s.barShutdownQueue, b.shutdown)
172172 }:
173173 case <-p.done:
174174 }
268268 // shutdown at next flush, in other words decrement underlying WaitGroup
269269 // only after the bar with completed state has been flushed. this
270270 // ensures no bar ends up with less than 100% rendered.
271 s.shutdownPending = append(s.shutdownPending, bar)
271 s.barShutdownQueue = append(s.barShutdownQueue, bar.shutdown)
272272 if parkedBar := s.parkedBars[bar]; parkedBar != nil {
273273 heap.Push(s.bHeap, parkedBar)
274274 s.heapUpdated = true
285285 lineCount += bar.extendedLines + 1
286286 }
287287
288 for i := len(s.shutdownPending) - 1; i >= 0; i-- {
289 close(s.shutdownPending[i].shutdown)
290 s.shutdownPending = s.shutdownPending[:i]
288 for i := len(s.barShutdownQueue) - 1; i >= 0; i-- {
289 close(s.barShutdownQueue[i])
290 s.barShutdownQueue = s.barShutdownQueue[:i]
291291 }
292292
293293 return cw.Flush(lineCount)