Codebase list golang-github-vbauerster-mpb / f9454a0
avoid *frameReader type assertion Vladimir Bauer 7 years ago
3 changed file(s) with 12 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
3535 operateState chan func(*bState)
3636 int64Ch chan int64
3737 boolCh chan bool
38 frameReaderCh chan io.Reader
38 frameReaderCh chan *frameReader
3939 syncTableCh chan [][]chan int
4040 bufNL *bytes.Buffer
4141
109109 operateState: make(chan func(*bState)),
110110 int64Ch: make(chan int64),
111111 boolCh: make(chan bool),
112 frameReaderCh: make(chan io.Reader, 1),
112 frameReaderCh: make(chan *frameReader, 1),
113113 syncTableCh: make(chan [][]chan int),
114114 done: make(chan struct{}),
115115 shutdown: make(chan struct{}),
2626 type Writer struct {
2727 out io.Writer
2828 buf bytes.Buffer
29 lineSep []byte
2930 lineCount int
3031 }
3132
3233 // New returns a new Writer with defaults
3334 func New(w io.Writer) *Writer {
34 return &Writer{out: w}
35 return &Writer{
36 out: w,
37 lineSep: []byte("\n"),
38 }
3539 }
3640
3741 // Flush flushes the underlying buffer
3842 func (w *Writer) Flush() error {
3943 err := w.clearLines()
40 w.lineCount = bytes.Count(w.buf.Bytes(), []byte("\n"))
44 w.lineCount = bytes.Count(w.buf.Bytes(), w.lineSep)
4145 // WriteTo takes care of w.buf.Reset
4246 if _, e := w.buf.WriteTo(w.out); err == nil {
4347 err = e
200200 func (s *pState) flush() (err error) {
201201 for s.bHeap.Len() > 0 {
202202 bar := heap.Pop(s.bHeap).(*Bar)
203 reader := <-bar.frameReaderCh
204 if _, e := s.cw.ReadFrom(reader); e != nil {
203 frameReader := <-bar.frameReaderCh
204 if _, e := s.cw.ReadFrom(frameReader); e != nil {
205205 err = e
206206 }
207207 defer func() {
208 if frame, ok := reader.(*frameReader); ok && frame.toShutdown {
208 if frameReader.toShutdown {
209209 // shutdown at next flush, in other words decrement underlying WaitGroup
210210 // only after the bar with completed state has been flushed.
211211 // this ensures no bar ends up with less than 100% rendered.
215215 s.heapUpdated = true
216216 delete(s.waitBars, bar)
217217 }
218 if frame.removeOnComplete {
218 if frameReader.removeOnComplete {
219219 s.heapUpdated = true
220220 return
221221 }