Codebase list golang-github-vbauerster-mpb / 74ea840
refactoring: frameReader to bFrame Vladimir Bauer 7 years ago
2 changed file(s) with 29 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
3333 priority int
3434 index int
3535
36 runningBar *Bar
37 cacheState *bState
38 operateState chan func(*bState)
39 int64Ch chan int64
40 boolCh chan bool
41 frameReaderCh chan *frameReader
42 syncTableCh chan [][]chan int
36 runningBar *Bar
37 cacheState *bState
38 operateState chan func(*bState)
39 int64Ch chan int64
40 boolCh chan bool
41 bFrameCh chan *bFrame
42 syncTableCh chan [][]chan int
4343
4444 // done is closed by Bar's goroutine, after cacheState is written
4545 done chan struct{}
7373 priority int
7474 runningBar *Bar
7575 }
76 frameReader struct {
77 io.Reader
76 bFrame struct {
77 rd io.Reader
7878 extendedLines int
7979 toShutdown bool
8080 removeOnComplete bool
115115 }
116116
117117 b := &Bar{
118 priority: s.priority,
119 runningBar: s.runningBar,
120 operateState: make(chan func(*bState)),
121 int64Ch: make(chan int64),
122 boolCh: make(chan bool),
123 frameReaderCh: make(chan *frameReader, 1),
124 syncTableCh: make(chan [][]chan int),
125 done: make(chan struct{}),
126 shutdown: make(chan struct{}),
118 priority: s.priority,
119 runningBar: s.runningBar,
120 operateState: make(chan func(*bState)),
121 int64Ch: make(chan int64),
122 boolCh: make(chan bool),
123 bFrameCh: make(chan *bFrame, 1),
124 syncTableCh: make(chan [][]chan int),
125 done: make(chan struct{}),
126 shutdown: make(chan struct{}),
127127 }
128128
129129 if b.runningBar != nil {
283283 if p := recover(); p != nil {
284284 s.panicMsg = fmt.Sprintf("panic: %v", p)
285285 fmt.Fprintf(debugOut, "%s %s bar id %02d %v\n", "[mpb]", time.Now(), s.id, s.panicMsg)
286 b.frameReaderCh <- &frameReader{
287 Reader: strings.NewReader(fmt.Sprintf(fmt.Sprintf("%%.%ds\n", tw), s.panicMsg)),
286 b.bFrameCh <- &bFrame{
287 rd: strings.NewReader(fmt.Sprintf(fmt.Sprintf("%%.%ds\n", tw), s.panicMsg)),
288288 toShutdown: true,
289289 }
290290 }
296296 extendedLines = countLines(s.bufE.Bytes())
297297 r = io.MultiReader(r, s.bufE)
298298 }
299 b.frameReaderCh <- &frameReader{
300 Reader: r,
299 b.bFrameCh <- &bFrame{
300 rd: r,
301301 extendedLines: extendedLines,
302302 toShutdown: s.toComplete && !s.completeFlushed,
303303 removeOnComplete: s.removeOnComplete,
313313 extendedLines = countLines(s.bufE.Bytes())
314314 r = io.MultiReader(r, s.bufE)
315315 }
316 b.frameReaderCh <- &frameReader{
317 Reader: r,
316 b.bFrameCh <- &bFrame{
317 rd: r,
318318 extendedLines: extendedLines,
319319 }
320320 }
229229 var lineCount int
230230 for s.bHeap.Len() > 0 {
231231 bar := heap.Pop(s.bHeap).(*Bar)
232 frameReader := <-bar.frameReaderCh
232 frame := <-bar.bFrameCh
233233 defer func() {
234 if frameReader.toShutdown {
234 if frame.toShutdown {
235235 // force next refresh asap, without waiting for ticker
236236 go func() {
237237 select {
249249 s.heapUpdated = true
250250 delete(s.waitBars, bar)
251251 }
252 if frameReader.removeOnComplete {
252 if frame.removeOnComplete {
253253 s.heapUpdated = true
254254 return
255255 }
256256 }
257257 heap.Push(s.bHeap, bar)
258258 }()
259 cw.ReadFrom(frameReader)
260 lineCount += frameReader.extendedLines + 1
259 cw.ReadFrom(frame.rd)
260 lineCount += frame.extendedLines + 1
261261 }
262262
263263 for i := len(s.shutdownPending) - 1; i >= 0; i-- {