diff --git a/_examples/cancel/main.go b/_examples/cancel/main.go index 1528ffd..b53085a 100644 --- a/_examples/cancel/main.go +++ b/_examples/cancel/main.go @@ -39,7 +39,7 @@ defer wg.Done() rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond - for !bar.Completed() { + for bar.IsRunning() { // start variable is solely for EWMA calculation // EWMA's unit of measure is an iteration's duration start := time.Now() diff --git a/_examples/remove/main.go b/_examples/remove/main.go index 416df82..96d306c 100644 --- a/_examples/remove/main.go +++ b/_examples/remove/main.go @@ -41,7 +41,7 @@ defer wg.Done() rng := rand.New(rand.NewSource(time.Now().UnixNano())) max := 100 * time.Millisecond - for i := 0; !bar.Completed(); i++ { + for i := 0; bar.IsRunning(); i++ { if bar.ID() == 2 && i >= 42 { bar.Abort(false) } diff --git a/bar.go b/bar.go index 0c95b2c..2f5ba9a 100644 --- a/bar.go +++ b/bar.go @@ -418,7 +418,7 @@ func (b *Bar) forceRefresh() { var anyOtherRunning bool b.container.traverseBars(func(bar *Bar) bool { - anyOtherRunning = b != bar && bar.isRunning() + anyOtherRunning = b != bar && bar.IsRunning() return !anyOtherRunning }) if !anyOtherRunning { @@ -433,7 +433,9 @@ } } -func (b *Bar) isRunning() bool { +// IsRunning reports whether the bar is running, i.e. not yet completed +// and not yet aborted. +func (b *Bar) IsRunning() bool { result := make(chan bool) select { case b.operateState <- func(s *bState) {