rename externalRefresh to manualRefresh
Vladimir Bauer
3 years ago
| 51 | 51 | filler BarFiller |
| 52 | 52 | middleware func(BarFiller) BarFiller |
| 53 | 53 | extender extenderFunc |
| 54 | refreshCh chan interface{} | |
| 54 | manualRefresh chan interface{} | |
| 55 | 55 | |
| 56 | 56 | wait struct { |
| 57 | 57 | bar *Bar // key for (*pState).queueBars |
| 184 | 184 | if s.current >= s.total { |
| 185 | 185 | s.current = s.total |
| 186 | 186 | s.completed = true |
| 187 | go b.forceRefresh(s.refreshCh) | |
| 187 | go b.forceRefresh(s.manualRefresh) | |
| 188 | 188 | } else { |
| 189 | 189 | s.triggerComplete = true |
| 190 | 190 | } |
| 212 | 212 | if triggerCompleteNow { |
| 213 | 213 | s.current = s.total |
| 214 | 214 | s.completed = true |
| 215 | go b.forceRefresh(s.refreshCh) | |
| 215 | go b.forceRefresh(s.manualRefresh) | |
| 216 | 216 | } |
| 217 | 217 | }: |
| 218 | 218 | case <-b.done: |
| 229 | 229 | if s.triggerComplete && s.current >= s.total { |
| 230 | 230 | s.current = s.total |
| 231 | 231 | s.completed = true |
| 232 | go b.forceRefresh(s.refreshCh) | |
| 232 | go b.forceRefresh(s.manualRefresh) | |
| 233 | 233 | } |
| 234 | 234 | }: |
| 235 | 235 | case <-b.done: |
| 258 | 258 | if s.triggerComplete && s.current >= s.total { |
| 259 | 259 | s.current = s.total |
| 260 | 260 | s.completed = true |
| 261 | go b.forceRefresh(s.refreshCh) | |
| 261 | go b.forceRefresh(s.manualRefresh) | |
| 262 | 262 | } |
| 263 | 263 | }: |
| 264 | 264 | case <-b.done: |
| 318 | 318 | } |
| 319 | 319 | s.aborted = true |
| 320 | 320 | s.dropOnComplete = drop |
| 321 | go b.forceRefresh(s.refreshCh) | |
| 321 | go b.forceRefresh(s.manualRefresh) | |
| 322 | 322 | }: |
| 323 | 323 | case <-b.done: |
| 324 | 324 | } |
| 40 | 40 | // Refresh will occur upon receive value from provided ch. |
| 41 | 41 | func WithManualRefresh(ch chan interface{}) ContainerOption { |
| 42 | 42 | return func(s *pState) { |
| 43 | s.externalRefresh = ch | |
| 43 | s.manualRefresh = ch | |
| 44 | 44 | s.disableAutoRefresh = true |
| 45 | 45 | } |
| 46 | 46 | } |
| 52 | 52 | popCompleted bool |
| 53 | 53 | outputDiscarded bool |
| 54 | 54 | disableAutoRefresh bool |
| 55 | externalRefresh chan interface{} | |
| 55 | manualRefresh chan interface{} | |
| 56 | 56 | renderDelay <-chan struct{} |
| 57 | 57 | shutdownNotifier chan struct{} |
| 58 | 58 | queueBars map[*Bar]*Bar |
| 73 | 73 | func NewWithContext(ctx context.Context, options ...ContainerOption) *Progress { |
| 74 | 74 | ctx, cancel := context.WithCancel(ctx) |
| 75 | 75 | s := &pState{ |
| 76 | rr: prr, | |
| 77 | bHeap: priorityQueue{}, | |
| 78 | rows: make([]io.Reader, 0, 64), | |
| 79 | pool: make([]*Bar, 0, 64), | |
| 80 | externalRefresh: make(chan interface{}), | |
| 81 | queueBars: make(map[*Bar]*Bar), | |
| 82 | popPriority: math.MinInt32, | |
| 83 | output: os.Stdout, | |
| 84 | debugOut: io.Discard, | |
| 76 | rr: prr, | |
| 77 | bHeap: priorityQueue{}, | |
| 78 | rows: make([]io.Reader, 0, 64), | |
| 79 | pool: make([]*Bar, 0, 64), | |
| 80 | manualRefresh: make(chan interface{}), | |
| 81 | queueBars: make(map[*Bar]*Bar), | |
| 82 | popPriority: math.MinInt32, | |
| 83 | output: os.Stdout, | |
| 84 | debugOut: io.Discard, | |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | for _, opt := range options { |
| 391 | 391 | select { |
| 392 | 392 | case t := <-autoRefresh: |
| 393 | 393 | ch <- t |
| 394 | case x := <-s.externalRefresh: | |
| 394 | case x := <-s.manualRefresh: | |
| 395 | 395 | if t, ok := x.(time.Time); ok { |
| 396 | 396 | ch <- t |
| 397 | 397 | } else { |
| 426 | 426 | |
| 427 | 427 | func (s *pState) makeBarState(total int64, filler BarFiller, options ...BarOption) *bState { |
| 428 | 428 | bs := &bState{ |
| 429 | id: s.idCount, | |
| 430 | priority: s.idCount, | |
| 431 | reqWidth: s.reqWidth, | |
| 432 | total: total, | |
| 433 | filler: filler, | |
| 434 | refreshCh: s.externalRefresh, | |
| 429 | id: s.idCount, | |
| 430 | priority: s.idCount, | |
| 431 | reqWidth: s.reqWidth, | |
| 432 | total: total, | |
| 433 | filler: filler, | |
| 434 | manualRefresh: s.manualRefresh, | |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | if total > 0 { |