Better stop uncompleted bars
Vladimir Bauer
9 years ago
| 61 | 61 | // WaitGroup for internal rendering sync |
| 62 | 62 | wg *sync.WaitGroup |
| 63 | 63 | |
| 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{} | |
| 70 | 70 | |
| 71 | 71 | // follawing is used after (*Progress.done) is closed |
| 72 | 72 | conf userConf |
| 77 | 77 | // If you don't plan to cancel, it is safe to feed with nil |
| 78 | 78 | func New() *Progress { |
| 79 | 79 | 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{}), | |
| 87 | 87 | } |
| 88 | 88 | go p.server(userConf{ |
| 89 | 89 | width: pwidth, |
| 213 | 213 | return |
| 214 | 214 | default: |
| 215 | 215 | // complet Total unknown bars |
| 216 | p.totalUnknownBarStopReqCh <- struct{}{} | |
| 216 | p.uncompletedBarStopReqCh <- struct{}{} | |
| 217 | 217 | // wait for all bars to quit |
| 218 | 218 | p.wg.Wait() |
| 219 | 219 | // stop request |
| 332 | 332 | for _, b := range bars { |
| 333 | 333 | b.flushed() |
| 334 | 334 | } |
| 335 | case <-p.totalUnknownBarStopReqCh: | |
| 335 | case <-p.uncompletedBarStopReqCh: | |
| 336 | 336 | for _, b := range bars { |
| 337 | if b.GetStatistics().Total <= 0 { | |
| 337 | stat := b.GetStatistics() | |
| 338 | if !stat.Completed { | |
| 338 | 339 | b.Completed() |
| 339 | 340 | } |
| 340 | 341 | } |