Issue #7: call b.Completed() implicitly, if total <= 0
Vladimir Bauer
9 years ago
| 64 | 64 | barCountReqCh chan chan int |
| 65 | 65 | brCh chan BeforeRender |
| 66 | 66 | done chan struct{} |
| 67 | beforeStop chan struct{} | |
| 67 | 68 | cancel <-chan struct{} |
| 68 | 69 | } |
| 69 | 70 | |
| 79 | 80 | barCountReqCh: make(chan chan int), |
| 80 | 81 | brCh: make(chan BeforeRender), |
| 81 | 82 | done: make(chan struct{}), |
| 83 | beforeStop: make(chan struct{}), | |
| 82 | 84 | wg: new(sync.WaitGroup), |
| 83 | 85 | } |
| 84 | 86 | go p.server() |
| 197 | 199 | // 100 %. It is NOT for cancelation. Use WithContext or WithCancel for |
| 198 | 200 | // cancelation purposes. |
| 199 | 201 | func (p *Progress) Stop() { |
| 202 | if isClosed(p.done) { | |
| 203 | return | |
| 204 | } | |
| 205 | p.beforeStop <- struct{}{} | |
| 200 | 206 | p.wg.Wait() |
| 201 | if isClosed(p.done) { | |
| 202 | return | |
| 203 | } | |
| 204 | 207 | close(p.bCommandCh) |
| 205 | 208 | } |
| 206 | 209 | |
| 297 | 300 | case userRR = <-p.rrChangeReqCh: |
| 298 | 301 | t.Stop() |
| 299 | 302 | t = time.NewTicker(userRR) |
| 303 | case <-p.beforeStop: | |
| 304 | for _, b := range bars { | |
| 305 | if b.GetStatistics().Total <= 0 { | |
| 306 | b.Completed() | |
| 307 | } | |
| 308 | } | |
| 300 | 309 | case <-p.cancel: |
| 301 | 310 | return |
| 302 | 311 | } |