diff --git a/bar.go b/bar.go index 2bf2b59..3cafb07 100644 --- a/bar.go +++ b/bar.go @@ -106,7 +106,7 @@ operateState: make(chan func(*bState)), frameCh: make(chan io.Reader, 1), syncTableCh: make(chan [][]chan int), - completed: make(chan bool), + completed: make(chan bool, 1), done: make(chan struct{}), cancel: cancel, dlogger: log.New(bs.debugOut, logPrefix, log.Lshortfile), @@ -256,8 +256,8 @@ // Completed reports whether the bar is in completed state. func (b *Bar) Completed() bool { select { - case completed := <-b.completed: - return completed + case b.operateState <- func(s *bState) { b.completed <- s.toComplete }: + return <-b.completed case <-b.done: return true } @@ -278,7 +278,6 @@ select { case op := <-b.operateState: op(s) - case b.completed <- s.toComplete: case <-ctx.Done(): b.cacheState = s close(b.done)