Skip to content

Commit

Permalink
don't create cwriter.New(io.Discard) unless delayRC is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
vbauerster committed Dec 26, 2023
1 parent 8feb9fa commit a3f0fb1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ func NewWithContext(ctx context.Context, options ...ContainerOption) *Progress {
ctx = context.Background()
}
ctx, cancel := context.WithCancel(ctx)
delayRC := make(chan struct{}, 1)
delayRC <- struct{}{}
s := &pState{
ctx: ctx,
hm: make(heapManager),
Expand All @@ -78,7 +76,6 @@ func NewWithContext(ctx context.Context, options ...ContainerOption) *Progress {
renderReq: make(chan time.Time),
popPriority: math.MinInt32,
refreshRate: defaultRefreshRate,
delayRC: delayRC,
queueBars: make(map[*Bar]*Bar),
output: os.Stdout,
debugOut: io.Discard,
Expand Down Expand Up @@ -262,11 +259,17 @@ func (p *Progress) Shutdown() {
func (p *Progress) serve(s *pState, cw *cwriter.Writer) {
defer p.pwg.Done()
var err error
w := cwriter.New(io.Discard)
var w *cwriter.Writer
renderReq := s.renderReq
operateState := p.operateState
interceptIO := p.interceptIO

if s.delayRC != nil {
w = cwriter.New(io.Discard)
} else {
w, cw = cw, nil
}

for {
select {
case <-s.delayRC:
Expand Down

0 comments on commit a3f0fb1

Please sign in to comment.