Codebase list golang-github-vbauerster-mpb / c18b35e
Refactoring: better check for uncompleted bars Vladimir Bauer 9 years ago
2 changed file(s) with 12 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
2626 completeReqCh chan struct{}
2727 removeReqCh chan struct{}
2828 done chan struct{}
29 completed chan struct{}
29 inProgress chan struct{}
3030 cancel <-chan struct{}
3131
3232 // follawing are used after (*Bar.done) is closed
3939 type Statistics struct {
4040 ID int
4141 Completed bool
42 Aborted bool
4243 Total int64
4344 Current int64
4445 StartTime time.Time
7273 trimLeftSpace bool
7374 trimRightSpace bool
7475 completed bool
76 aborted bool
7577 startTime time.Time
7678 timeElapsed time.Duration
7779 timePerItem time.Duration
9193 removeReqCh: make(chan struct{}),
9294 completeReqCh: make(chan struct{}),
9395 done: make(chan struct{}),
94 completed: make(chan struct{}),
96 inProgress: make(chan struct{}),
9597 cancel: conf.cancel,
9698 }
9799
236238 // Can be used as condition in for loop
237239 func (b *Bar) InProgress() bool {
238240 select {
239 case <-b.completed:
241 case <-b.inProgress:
240242 return false
241243 default:
242244 return true
323325 s.updateTimePerItemEstimate(incrStartTime, r.amount)
324326 if n == s.total {
325327 s.completed = true
326 close(b.completed)
328 close(b.inProgress)
327329 }
328330 s.current = n
329331 if r.refill != nil {
341343 case <-b.removeReqCh:
342344 return
343345 case <-b.cancel:
344 close(b.completed)
346 s.aborted = true
347 close(b.inProgress)
345348 return
346349 }
347350 }
491494 return &Statistics{
492495 ID: s.id,
493496 Completed: s.completed,
497 Aborted: s.aborted,
494498 Total: s.total,
495499 Current: s.current,
496500 StartTime: s.startTime,
334334 }
335335 case <-p.uncompletedBarStopReqCh:
336336 for _, b := range bars {
337 stat := b.GetStatistics()
338 if !stat.Completed {
339 b.Completed()
337 s := b.getState()
338 if !s.completed && !s.aborted {
339 b.Complete()
340340 }
341341 }
342342 case <-p.stopReqCh: