Codebase list golang-github-vbauerster-mpb / f863d06
Better stop uncompleted bars Vladimir Bauer 9 years ago
1 changed file(s) with 17 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
6161 // WaitGroup for internal rendering sync
6262 wg *sync.WaitGroup
6363
64 done chan struct{}
65 userConfCh chan userConf
66 bCommandCh chan *bCommandData
67 barCountCh chan int
68 stopReqCh chan struct{}
69 totalUnknownBarStopReqCh chan struct{}
64 done chan struct{}
65 userConfCh chan userConf
66 bCommandCh chan *bCommandData
67 barCountCh chan int
68 stopReqCh chan struct{}
69 uncompletedBarStopReqCh chan struct{}
7070
7171 // follawing is used after (*Progress.done) is closed
7272 conf userConf
7777 // If you don't plan to cancel, it is safe to feed with nil
7878 func New() *Progress {
7979 p := &Progress{
80 wg: new(sync.WaitGroup),
81 done: make(chan struct{}),
82 userConfCh: make(chan userConf),
83 bCommandCh: make(chan *bCommandData),
84 barCountCh: make(chan int),
85 stopReqCh: make(chan struct{}),
86 totalUnknownBarStopReqCh: make(chan struct{}),
80 wg: new(sync.WaitGroup),
81 done: make(chan struct{}),
82 userConfCh: make(chan userConf),
83 bCommandCh: make(chan *bCommandData),
84 barCountCh: make(chan int),
85 stopReqCh: make(chan struct{}),
86 uncompletedBarStopReqCh: make(chan struct{}),
8787 }
8888 go p.server(userConf{
8989 width: pwidth,
213213 return
214214 default:
215215 // complet Total unknown bars
216 p.totalUnknownBarStopReqCh <- struct{}{}
216 p.uncompletedBarStopReqCh <- struct{}{}
217217 // wait for all bars to quit
218218 p.wg.Wait()
219219 // stop request
332332 for _, b := range bars {
333333 b.flushed()
334334 }
335 case <-p.totalUnknownBarStopReqCh:
335 case <-p.uncompletedBarStopReqCh:
336336 for _, b := range bars {
337 if b.GetStatistics().Total <= 0 {
337 stat := b.GetStatistics()
338 if !stat.Completed {
338339 b.Completed()
339340 }
340341 }