refactoring: triggerCompletion as method of bState
Vladimir Bauer
1 year, 10 months ago
| 189 | 189 | if s.current >= s.total { |
| 190 | 190 | s.current = s.total |
| 191 | 191 | s.completed = true |
| 192 | b.triggerCompletion(s) | |
| 192 | s.triggerCompletion(b) | |
| 193 | 193 | } else { |
| 194 | 194 | s.triggerComplete = true |
| 195 | 195 | } |
| 217 | 217 | if complete { |
| 218 | 218 | s.current = s.total |
| 219 | 219 | s.completed = true |
| 220 | b.triggerCompletion(s) | |
| 220 | s.triggerCompletion(b) | |
| 221 | 221 | } |
| 222 | 222 | }: |
| 223 | 223 | case <-b.ctx.Done(): |
| 235 | 235 | if s.triggerComplete && s.current >= s.total { |
| 236 | 236 | s.current = s.total |
| 237 | 237 | s.completed = true |
| 238 | b.triggerCompletion(s) | |
| 238 | s.triggerCompletion(b) | |
| 239 | 239 | } |
| 240 | 240 | }: |
| 241 | 241 | case <-b.ctx.Done(): |
| 257 | 257 | if s.triggerComplete && s.current >= s.total { |
| 258 | 258 | s.current = s.total |
| 259 | 259 | s.completed = true |
| 260 | b.triggerCompletion(s) | |
| 260 | s.triggerCompletion(b) | |
| 261 | 261 | } |
| 262 | 262 | result <- &wg |
| 263 | 263 | }: |
| 285 | 285 | if s.triggerComplete && s.current >= s.total { |
| 286 | 286 | s.current = s.total |
| 287 | 287 | s.completed = true |
| 288 | b.triggerCompletion(s) | |
| 288 | s.triggerCompletion(b) | |
| 289 | 289 | } |
| 290 | 290 | }: |
| 291 | 291 | case <-b.ctx.Done(): |
| 314 | 314 | if s.triggerComplete && s.current >= s.total { |
| 315 | 315 | s.current = s.total |
| 316 | 316 | s.completed = true |
| 317 | b.triggerCompletion(s) | |
| 317 | s.triggerCompletion(b) | |
| 318 | 318 | } |
| 319 | 319 | result <- &wg |
| 320 | 320 | }: |
| 360 | 360 | } |
| 361 | 361 | s.aborted = true |
| 362 | 362 | s.rmOnComplete = drop |
| 363 | b.triggerCompletion(s) | |
| 363 | s.triggerCompletion(b) | |
| 364 | 364 | }: |
| 365 | 365 | case <-b.ctx.Done(): |
| 366 | 366 | } |
| 449 | 449 | case b.operateState <- fn: |
| 450 | 450 | case <-b.bsOk: |
| 451 | 451 | fn(b.bs) |
| 452 | } | |
| 453 | } | |
| 454 | ||
| 455 | func (b *Bar) triggerCompletion(s *bState) { | |
| 456 | if s.autoRefresh { | |
| 457 | // Technically this call isn't required, but if refresh rate is set to | |
| 458 | // one hour for example and bar completes within a few minutes p.Wait() | |
| 459 | // will wait for one hour. This call helps to avoid unnecessary waiting. | |
| 460 | go b.tryEarlyRefresh(s.renderReq) | |
| 461 | } else { | |
| 462 | b.cancel() | |
| 463 | 452 | } |
| 464 | 453 | } |
| 465 | 454 | |
| 568 | 557 | return table |
| 569 | 558 | } |
| 570 | 559 | |
| 560 | func (s bState) triggerCompletion(b *Bar) { | |
| 561 | if s.autoRefresh { | |
| 562 | // Technically this call isn't required, but if refresh rate is set to | |
| 563 | // one hour for example and bar completes within a few minutes p.Wait() | |
| 564 | // will wait for one hour. This call helps to avoid unnecessary waiting. | |
| 565 | go b.tryEarlyRefresh(s.renderReq) | |
| 566 | } else { | |
| 567 | b.cancel() | |
| 568 | } | |
| 569 | } | |
| 570 | ||
| 571 | 571 | func (s bState) decoratorEwmaUpdate(n int64, dur time.Duration, wg *sync.WaitGroup) { |
| 572 | 572 | for i := 0; i < len(s.ewmaDecorators); i++ { |
| 573 | 573 | wg.Add(1) |