Codebase list golang-github-vbauerster-mpb / 0e47f1a
BarNoPop BarOption Vladimir Bauer 7 years ago
3 changed file(s) with 25 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
3737 extendedLines int
3838 toShutdown bool
3939 toDrop bool
40 noPop bool
4041 operateState chan func(*bState)
4142 frameCh chan io.Reader
4243 syncTableCh chan [][]chan int
7071 toComplete bool
7172 completeFlushed bool
7273 noBufBOnComplete bool
74 noPop bool
7375 aDecorators []decor.Decorator
7476 pDecorators []decor.Decorator
7577 amountReceivers []decor.AmountReceiver
102104 container: container,
103105 priority: bs.priority,
104106 toDrop: bs.dropOnComplete,
107 noPop: bs.noPop,
105108 operateState: make(chan func(*bState)),
106109 frameCh: make(chan io.Reader, 1),
107110 syncTableCh: make(chan [][]chan int),
166166 return MakeFillerTypeSpecificBarOption(chk, cb)
167167 }
168168
169 // BarNoPop disables bar pop out of container. Effective when
170 // PopCompletedMode of container is enabled.
171 func BarNoPop() BarOption {
172 return func(s *bState) {
173 s.noPop = true
174 }
175 }
176
169177 // BarReverse reverse mode, bar will progress from right to left.
170178 func BarReverse() BarOption {
171179 chk := func(filler Filler) (interface{}, bool) {
260260
261261 func (s *pState) flush(cw *cwriter.Writer) error {
262262 var lineCount int
263 hlen := s.bHeap.Len()
264 bb := make([]*Bar, hlen)
265 for i := 0; i < hlen; i++ {
263 bm := make(map[*Bar]struct{}, s.bHeap.Len())
264 for s.bHeap.Len() > 0 {
266265 b := heap.Pop(&s.bHeap).(*Bar)
267266 defer func() {
268267 if b.toShutdown {
277276 }()
278277 cw.ReadFrom(<-b.frameCh)
279278 lineCount += b.extendedLines + 1
280 bb[i] = b
281 }
282
283 for _, b := range bb {
284 heap.Push(&s.bHeap, b)
279 bm[b] = struct{}{}
285280 }
286281
287282 for _, b := range s.barShutdownQueue {
292287 b.toDrop = true
293288 }
294289 if b.toDrop {
295 heap.Remove(&s.bHeap, b.index)
290 delete(bm, b)
296291 s.heapUpdated = true
297292 } else if s.popCompleted {
298 defer func() {
299 s.barPopQueue = append(s.barPopQueue, b)
300 }()
293 if !b.noPop {
294 defer func() {
295 s.barPopQueue = append(s.barPopQueue, b)
296 }()
297 }
301298 }
302299 b.cancel()
303300 }
304301 s.barShutdownQueue = s.barShutdownQueue[0:0]
305302
306303 for _, b := range s.barPopQueue {
307 heap.Remove(&s.bHeap, b.index)
304 delete(bm, b)
308305 s.heapUpdated = true
309306 lineCount -= b.extendedLines + 1
310307 }
311308 s.barPopQueue = s.barPopQueue[0:0]
309
310 for b := range bm {
311 heap.Push(&s.bHeap, b)
312 }
312313
313314 return cw.Flush(lineCount)
314315 }