From 7e6af46af0dd65dfcb6596c2e919b0914475b43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20D=C3=B6tsch?= Date: Thu, 30 Sep 2021 16:33:13 +0200 Subject: [PATCH] stop time.Ticker after use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matthias Dötsch --- pkg/progress/tty.go | 5 +++-- pkg/progress/tty_test.go | 2 +- pkg/progress/writer.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/progress/tty.go b/pkg/progress/tty.go index 293e42b0e..5fe4270b9 100644 --- a/pkg/progress/tty.go +++ b/pkg/progress/tty.go @@ -38,12 +38,13 @@ type ttyWriter struct { repeated bool numLines int done chan bool - mtx *sync.RWMutex + mtx *sync.Mutex tailEvents []string } func (w *ttyWriter) Start(ctx context.Context) error { ticker := time.NewTicker(100 * time.Millisecond) + defer ticker.Stop() for { select { @@ -188,7 +189,7 @@ func lineText(event Event, pad string, terminalWidth, statusPadding int, color b padding = 0 } // calculate the max length for the status text, on errors it - // is 2-3 lines long and breaks the line formating + // is 2-3 lines long and breaks the line formatting maxStatusLen := terminalWidth - textLen - statusPadding - 15 status := event.StatusText // in some cases (debugging under VS Code), terminalWidth is set to zero by goterm.Width() ; ensuring we don't tweak strings with negative char index diff --git a/pkg/progress/tty_test.go b/pkg/progress/tty_test.go index d95af857d..f9b4071d1 100644 --- a/pkg/progress/tty_test.go +++ b/pkg/progress/tty_test.go @@ -78,7 +78,7 @@ func TestLineTextSingleEvent(t *testing.T) { func TestErrorEvent(t *testing.T) { w := &ttyWriter{ events: map[string]Event{}, - mtx: &sync.RWMutex{}, + mtx: &sync.Mutex{}, } e := Event{ ID: "id", diff --git a/pkg/progress/writer.go b/pkg/progress/writer.go index 172de52f9..11d4044bb 100644 --- a/pkg/progress/writer.go +++ b/pkg/progress/writer.go @@ -105,7 +105,7 @@ func NewWriter(out console.File) (Writer, error) { events: map[string]Event{}, repeated: false, done: make(chan bool), - mtx: &sync.RWMutex{}, + mtx: &sync.Mutex{}, }, nil }