diff --git a/bar.go b/bar.go index 8b9072b..de14848 100644 --- a/bar.go +++ b/bar.go @@ -23,7 +23,6 @@ const ( cmdId = 1 << iota - cmdTotal cmdCurrent cmdALen cmdPLen @@ -42,7 +41,7 @@ runningBar *Bar cacheState *bState operateState chan func(*bState) - cmdValue chan int64 + cmdValue chan int frameReaderCh chan io.Reader // done is closed by Bar's goroutine, after cacheState is written @@ -117,7 +116,7 @@ priority: s.priority, runningBar: s.runningBar, operateState: make(chan func(*bState)), - cmdValue: make(chan int64), + cmdValue: make(chan int), frameReaderCh: make(chan io.Reader, 1), done: make(chan struct{}), shutdown: make(chan struct{}), @@ -160,7 +159,7 @@ func (b *Bar) NumOfAppenders() int { select { case b.cmdValue <- cmdALen: - return int(<-b.cmdValue) + return <-b.cmdValue case <-b.done: return len(b.cacheState.aDecorators) } @@ -170,7 +169,7 @@ func (b *Bar) NumOfPrependers() int { select { case b.cmdValue <- cmdPLen: - return int(<-b.cmdValue) + return <-b.cmdValue case <-b.done: return len(b.cacheState.pDecorators) } @@ -180,7 +179,7 @@ func (b *Bar) ID() int { select { case b.cmdValue <- cmdId: - return int(<-b.cmdValue) + return <-b.cmdValue case <-b.done: return b.cacheState.id } @@ -190,19 +189,9 @@ func (b *Bar) Current() int64 { select { case b.cmdValue <- cmdCurrent: - return <-b.cmdValue + return int64(<-b.cmdValue) case <-b.done: return b.cacheState.current - } -} - -// Total returns bar's total number. -func (b *Bar) Total() int64 { - select { - case b.cmdValue <- cmdTotal: - return <-b.cmdValue - case <-b.done: - return b.cacheState.total } } @@ -273,17 +262,15 @@ case cmd := <-b.cmdValue: switch { case cmd&cmdId != 0: - b.cmdValue <- int64(s.id) - case cmd&cmdTotal != 0: - b.cmdValue <- s.total + b.cmdValue <- s.id case cmd&cmdCurrent != 0: - b.cmdValue <- s.current + b.cmdValue <- int(s.current) case cmd&cmdPLen != 0: - b.cmdValue <- int64(len(s.pDecorators)) + b.cmdValue <- len(s.pDecorators) case cmd&cmdALen != 0: - b.cmdValue <- int64(len(s.aDecorators)) + b.cmdValue <- len(s.aDecorators) case cmd&cmdCompleted != 0: - var v int64 + var v int if s.toComplete { v = 1 } diff --git a/progress_go1.7_test.go b/progress_go1.7_test.go index 987cd52..6b4adda 100644 --- a/progress_go1.7_test.go +++ b/progress_go1.7_test.go @@ -20,10 +20,11 @@ mpb.WithShutdownNotifier(shutdown), ) + total := 1000 numBars := 3 bars := make([]*mpb.Bar, 0, numBars) for i := 0; i < numBars; i++ { - bar := p.AddBar(int64(1000), mpb.BarID(i)) + bar := p.AddBar(int64(total)) bars = append(bars, bar) go func() { for !bar.Completed() { @@ -37,8 +38,8 @@ p.Wait() for _, bar := range bars { - if bar.Current() >= bar.Total() { - t.Errorf("bar %d: total = %d, current = %d\n", bar.ID(), bar.Total(), bar.Current()) + if bar.Current() >= int64(total) { + t.Errorf("bar %d: total = %d, current = %d\n", bar.ID(), total, bar.Current()) } } select {