diff --git a/bar.go b/bar.go index 2ccd82a..4e226e3 100644 --- a/bar.go +++ b/bar.go @@ -22,6 +22,7 @@ done chan struct{} container *Progress bs *bState + ctx context.Context cancel func() } @@ -72,11 +73,12 @@ operateState: make(chan func(*bState)), done: make(chan struct{}), container: container, + ctx: ctx, cancel: cancel, } container.bwg.Add(1) - go bar.serve(ctx, bs) + go bar.serve(bs) return bar } @@ -386,13 +388,13 @@ <-b.done } -func (b *Bar) serve(ctx context.Context, bs *bState) { +func (b *Bar) serve(bs *bState) { defer b.container.bwg.Done() for { select { case op := <-b.operateState: op(bs) - case <-ctx.Done(): + case <-b.ctx.Done(): bs.aborted = !bs.completed bs.decoratorShutdownNotify() b.bs = bs