1
0
Эх сурвалжийг харах

stop time.Ticker after use

Signed-off-by: Matthias Dötsch <[email protected]>
Matthias Dötsch 4 жил өмнө
parent
commit
7e6af46af0

+ 3 - 2
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

+ 1 - 1
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",

+ 1 - 1
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
 	}