Codebase list golang-github-vbauerster-mpb / 717ae08
address issue #115 Vladimir Bauer 3 years ago
1 changed file(s) with 12 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
283283 }
284284
285285 func (s *pState) flush(cw *cwriter.Writer, height int) error {
286 var wg sync.WaitGroup
286287 var popCount int
287288 rows := make([]io.Reader, 0, height)
288289 pool := make([]*Bar, 0, s.bHeap.Len())
291292 b := heap.Pop(&s.bHeap).(*Bar)
292293 frame := <-b.frameCh
293294 for i := len(frame.rows) - 1; i >= 0; i-- {
294 if len(rows) == height {
295 break
296 }
297 rows = append(rows, frame.rows[i])
298 frameRowsUsed++
295 if len(rows) < height {
296 rows = append(rows, frame.rows[i])
297 frameRowsUsed++
298 } else {
299 wg.Add(1)
300 go func(discardRow io.Reader) {
301 _, _ = io.Copy(io.Discard, discardRow)
302 wg.Done()
303 }(frame.rows[i])
304 }
299305 }
300306 if frame.shutdown != 0 {
301307 b.Wait() // waiting for b.done, so it's safe to read b.bs
333339 }
334340 }
335341
342 wg.Wait()
336343 return cw.Flush(len(rows) - popCount)
337344 }
338345