Skip to content

Commit

Permalink
refactoring render error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vbauerster committed Dec 4, 2023
1 parent 4b59059 commit d078269
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ func (p *Progress) Shutdown() {

func (p *Progress) serve(s *pState, cw *cwriter.Writer) {
defer p.pwg.Done()
render := func() error { return s.render(cw) }
var err error
var renderReq <-chan time.Time

Expand All @@ -275,18 +274,26 @@ func (p *Progress) serve(s *pState, cw *cwriter.Writer) {
renderReq = s.renderReq
s.delayRC = nil
case <-renderReq:
e := render()
if e != nil {
err = s.render(cw)
if err != nil {
go func() {
for {
select {
case <-s.renderReq:
case <-p.done:
return
}
}
}()
p.cancel() // cancel all bars
render = func() error { return nil }
err = e
renderReq = nil
}
case <-p.done:
update := make(chan bool)
for s.autoRefresh && err == nil {
s.hm.state(update)
if <-update {
err = render()
err = s.render(cw)
} else {
break
}
Expand Down

0 comments on commit d078269

Please sign in to comment.