More precise barState.startTime
Vladimir Bauer
9 years ago
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | func (b *Bar) server(id int, total int64, width int, format string, wg *sync.WaitGroup, cancel <-chan struct{}) { |
| 275 | incrStartTime := time.Now() | |
| 275 | var incrStartTime time.Time | |
| 276 | 276 | barState := state{ |
| 277 | id: id, | |
| 278 | width: width, | |
| 279 | format: barFmtRunes{'[', '=', '>', '-', ']'}, | |
| 280 | etaAlpha: 0.25, | |
| 281 | total: total, | |
| 282 | startTime: incrStartTime, | |
| 283 | completed: false, | |
| 277 | id: id, | |
| 278 | width: width, | |
| 279 | format: barFmtRunes{'[', '=', '>', '-', ']'}, | |
| 280 | etaAlpha: 0.25, | |
| 281 | total: total, | |
| 284 | 282 | } |
| 285 | 283 | if total <= 0 { |
| 286 | 284 | barState.simpleSpinner = getSpinner() |
| 294 | 292 | for { |
| 295 | 293 | select { |
| 296 | 294 | case barState.incrAmount = <-b.incrCh: |
| 295 | if barState.current == 0 { | |
| 296 | incrStartTime = time.Now() | |
| 297 | barState.startTime = incrStartTime | |
| 298 | } | |
| 297 | 299 | n := barState.current + barState.incrAmount |
| 298 | 300 | if total > 0 && n > total { |
| 299 | 301 | barState.current = total |