| 37 | 37 |
heapUpdated bool
|
| 38 | 38 |
pMatrix map[int][]chan int
|
| 39 | 39 |
aMatrix map[int][]chan int
|
| 40 | |
barShutdownQueue []func()
|
|
40 |
barShutdownQueue []*Bar
|
| 41 | 41 |
|
| 42 | 42 |
// following are provided/overrided by user
|
| 43 | 43 |
idCount int
|
|
| 155 | 155 |
if b.index < 0 {
|
| 156 | 156 |
return
|
| 157 | 157 |
}
|
| 158 | |
s.heapUpdated = heap.Remove(&s.bHeap, b.index) != nil
|
|
158 |
heap.Remove(&s.bHeap, b.index)
|
|
159 |
s.heapUpdated = true
|
| 159 | 160 |
}:
|
| 160 | 161 |
case <-p.done:
|
| 161 | 162 |
}
|
|
| 253 | 254 |
}
|
| 254 | 255 |
|
| 255 | 256 |
func (s *pState) flush(cw *cwriter.Writer) error {
|
|
257 |
var rpop bool
|
| 256 | 258 |
var lineCount int
|
| 257 | |
for s.bHeap.Len() > 0 {
|
|
259 |
hlen := s.bHeap.Len()
|
|
260 |
tmp := make([]*Bar, hlen)
|
|
261 |
for i := 0; i < hlen; i++ {
|
| 258 | 262 |
bar := heap.Pop(&s.bHeap).(*Bar)
|
| 259 | 263 |
defer func() {
|
| 260 | 264 |
if bar.toShutdown {
|
| 261 | 265 |
// shutdown at next flush, in other words decrement underlying WaitGroup
|
| 262 | 266 |
// only after the bar with completed state has been flushed. this
|
| 263 | 267 |
// ensures no bar ends up with less than 100% rendered.
|
| 264 | |
s.barShutdownQueue = append(s.barShutdownQueue, bar.cancel)
|
| 265 | |
if parkedBar := s.parkedBars[bar]; parkedBar != nil {
|
| 266 | |
heap.Push(&s.bHeap, parkedBar)
|
| 267 | |
s.heapUpdated = true
|
| 268 | |
delete(s.parkedBars, bar)
|
| 269 | |
}
|
| 270 | |
if bar.toDrop {
|
| 271 | |
s.heapUpdated = true
|
| 272 | |
return
|
| 273 | |
}
|
| 274 | |
}
|
| 275 | |
heap.Push(&s.bHeap, bar)
|
|
268 |
s.barShutdownQueue = append(s.barShutdownQueue, bar)
|
|
269 |
// if parkedBar := s.parkedBars[bar]; parkedBar != nil {
|
|
270 |
// heap.Push(&s.bHeap, parkedBar)
|
|
271 |
// s.heapUpdated = true
|
|
272 |
// delete(s.parkedBars, bar)
|
|
273 |
// }
|
|
274 |
// if bar.toDrop {
|
|
275 |
// s.heapUpdated = true
|
|
276 |
// return
|
|
277 |
// }
|
|
278 |
// bar.priority = 0
|
|
279 |
}
|
| 276 | 280 |
}()
|
| 277 | 281 |
cw.ReadFrom(<-bar.frameCh)
|
| 278 | 282 |
lineCount += bar.extendedLines + 1
|
| 279 | |
}
|
| 280 | |
|
| 281 | |
for i := len(s.barShutdownQueue) - 1; i >= 0; i-- {
|
| 282 | |
s.barShutdownQueue[i]()
|
| 283 | |
s.barShutdownQueue = s.barShutdownQueue[:i]
|
| 284 | |
}
|
|
283 |
tmp[i] = bar
|
|
284 |
}
|
|
285 |
|
|
286 |
for _, b := range tmp {
|
|
287 |
heap.Push(&s.bHeap, b)
|
|
288 |
}
|
|
289 |
|
|
290 |
for _, b := range s.barShutdownQueue {
|
|
291 |
if parkedBar := s.parkedBars[b]; parkedBar != nil {
|
|
292 |
heap.Remove(&s.bHeap, b.index)
|
|
293 |
heap.Push(&s.bHeap, parkedBar)
|
|
294 |
delete(s.parkedBars, b)
|
|
295 |
s.heapUpdated = true
|
|
296 |
} else if b.toDrop {
|
|
297 |
heap.Remove(&s.bHeap, b.index)
|
|
298 |
s.heapUpdated = true
|
|
299 |
}
|
|
300 |
b.cancel()
|
|
301 |
}
|
|
302 |
s.barShutdownQueue = s.barShutdownQueue[0:0]
|
| 285 | 303 |
|
| 286 | 304 |
return cw.Flush(lineCount)
|
| 287 | 305 |
}
|