Skip to content

Commit c822af1

Browse files
committed
More precise barState.startTime
1 parent 5086a9d commit c822af1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

bar.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,13 @@ func (b *Bar) getState() state {
273273
}
274274

275275
func (b *Bar) server(id int, total int64, width int, format string, wg *sync.WaitGroup, cancel <-chan struct{}) {
276-
incrStartTime := time.Now()
276+
var incrStartTime time.Time
277277
barState := state{
278-
id: id,
279-
width: width,
280-
format: barFmtRunes{'[', '=', '>', '-', ']'},
281-
etaAlpha: 0.25,
282-
total: total,
283-
startTime: incrStartTime,
284-
completed: false,
278+
id: id,
279+
width: width,
280+
format: barFmtRunes{'[', '=', '>', '-', ']'},
281+
etaAlpha: 0.25,
282+
total: total,
285283
}
286284
if total <= 0 {
287285
barState.simpleSpinner = getSpinner()
@@ -295,6 +293,10 @@ func (b *Bar) server(id int, total int64, width int, format string, wg *sync.Wai
295293
for {
296294
select {
297295
case barState.incrAmount = <-b.incrCh:
296+
if barState.current == 0 {
297+
incrStartTime = time.Now()
298+
barState.startTime = incrStartTime
299+
}
298300
n := barState.current + barState.incrAmount
299301
if total > 0 && n > total {
300302
barState.current = total

0 commit comments

Comments
 (0)