Skip to content

Commit

Permalink
More precise barState.startTime
Browse files Browse the repository at this point in the history
  • Loading branch information
vbauerster committed Apr 20, 2017
1 parent 5086a9d commit c822af1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,13 @@ func (b *Bar) getState() state {
}

func (b *Bar) server(id int, total int64, width int, format string, wg *sync.WaitGroup, cancel <-chan struct{}) {
incrStartTime := time.Now()
var incrStartTime time.Time
barState := state{
id: id,
width: width,
format: barFmtRunes{'[', '=', '>', '-', ']'},
etaAlpha: 0.25,
total: total,
startTime: incrStartTime,
completed: false,
id: id,
width: width,
format: barFmtRunes{'[', '=', '>', '-', ']'},
etaAlpha: 0.25,
total: total,
}
if total <= 0 {
barState.simpleSpinner = getSpinner()
Expand All @@ -295,6 +293,10 @@ func (b *Bar) server(id int, total int64, width int, format string, wg *sync.Wai
for {
select {
case barState.incrAmount = <-b.incrCh:
if barState.current == 0 {
incrStartTime = time.Now()
barState.startTime = incrStartTime
}
n := barState.current + barState.incrAmount
if total > 0 && n > total {
barState.current = total
Expand Down

0 comments on commit c822af1

Please sign in to comment.