Codebase list golang-github-vbauerster-mpb / e6b8a4e
call b.stop in defer Vladimir Bauer 9 years ago
1 changed file(s) with 6 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
198198 }
199199
200200 func (b *Bar) server(ctx context.Context, wg *sync.WaitGroup, total int64) {
201 defer wg.Done()
202201 var completed bool
203 state := state{total: total}
204202 timeStarted := time.Now()
205203 blockStartTime := timeStarted
204 state := state{total: total}
205 defer func() {
206 b.stop(&state)
207 wg.Done()
208 }()
206209 for {
207210 select {
208211 case i := <-b.incrCh:
233236 case state.trimRightSpace = <-b.trimRightCh:
234237 case <-b.flushedCh:
235238 if completed {
236 b.stop(&state)
237239 return
238240 }
239241 case <-b.removeReqCh:
240 b.stop(&state)
241242 return
242243 case <-ctx.Done():
243 b.stop(&state)
244244 return
245245 }
246246 }
252252 }
253253
254254 func (b *Bar) draw(s state, termWidth int) []byte {
255
256255 buf := make([]byte, 0, termWidth)
256
257257 stat := &Statistics{
258258 Total: s.total,
259259 Current: s.current,
328328
329329 return buf
330330 }
331
332 // func (b *Bar) closeDone() {
333 // if !b.isDone() {
334 // close(b.done)
335 // }
336 // }
337331
338332 func (b *Bar) isDone() bool {
339333 select {