Skip to content

Commit

Permalink
fix: stop renderer before acquiring renderer mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jun 5, 2023
1 parent 444e04b commit 44f17fa
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions standard_renderer.go
Expand Up @@ -88,16 +88,18 @@ func (r *standardRenderer) start() {

// stop permanently halts the renderer, rendering the final frame.
func (r *standardRenderer) stop() {
// Stop the renderer before acquiring the mutex to avoid a deadlock.
r.once.Do(func() {
r.done <- struct{}{}
})

// flush locks the mutex
r.flush()

r.mtx.Lock()
defer r.mtx.Unlock()

r.out.ClearLine()
r.once.Do(func() {
r.done <- struct{}{}
})

if r.useANSICompressor {
if w, ok := r.out.TTY().(io.WriteCloser); ok {
Expand All @@ -108,13 +110,15 @@ func (r *standardRenderer) stop() {

// kill halts the renderer. The final frame will not be rendered.
func (r *standardRenderer) kill() {
// Stop the renderer before acquiring the mutex to avoid a deadlock.
r.once.Do(func() {
r.done <- struct{}{}
})

r.mtx.Lock()
defer r.mtx.Unlock()

r.out.ClearLine()
r.once.Do(func() {
r.done <- struct{}{}
})
}

// listen waits for ticks on the ticker, or a signal to stop the renderer.
Expand Down

0 comments on commit 44f17fa

Please sign in to comment.