stop time.Ticker after use

Signed-off-by: Matthias Dötsch <matthias.doetsch@innogames.com>
This commit is contained in:
Matthias Dötsch 2021-09-30 16:33:13 +02:00 committed by Nicolas De loof
parent 693732c4a7
commit 7e6af46af0
3 changed files with 5 additions and 4 deletions

View File

@ -38,12 +38,13 @@ type ttyWriter struct {
repeated bool repeated bool
numLines int numLines int
done chan bool done chan bool
mtx *sync.RWMutex mtx *sync.Mutex
tailEvents []string tailEvents []string
} }
func (w *ttyWriter) Start(ctx context.Context) error { func (w *ttyWriter) Start(ctx context.Context) error {
ticker := time.NewTicker(100 * time.Millisecond) ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
for { for {
select { select {
@ -188,7 +189,7 @@ func lineText(event Event, pad string, terminalWidth, statusPadding int, color b
padding = 0 padding = 0
} }
// calculate the max length for the status text, on errors it // 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 maxStatusLen := terminalWidth - textLen - statusPadding - 15
status := event.StatusText 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 // 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

View File

@ -78,7 +78,7 @@ func TestLineTextSingleEvent(t *testing.T) {
func TestErrorEvent(t *testing.T) { func TestErrorEvent(t *testing.T) {
w := &ttyWriter{ w := &ttyWriter{
events: map[string]Event{}, events: map[string]Event{},
mtx: &sync.RWMutex{}, mtx: &sync.Mutex{},
} }
e := Event{ e := Event{
ID: "id", ID: "id",

View File

@ -105,7 +105,7 @@ func NewWriter(out console.File) (Writer, error) {
events: map[string]Event{}, events: map[string]Event{},
repeated: false, repeated: false,
done: make(chan bool), done: make(chan bool),
mtx: &sync.RWMutex{}, mtx: &sync.Mutex{},
}, nil }, nil
} }