From df050472a1330dbaed8e4e85571db3300143f827 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 1 Feb 2020 12:23:56 +1100 Subject: more ticker improvements --- pkg/gui/app_status_manager.go | 4 +++- pkg/gui/gui.go | 4 +++- pkg/tasks/tasks.go | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'pkg') diff --git a/pkg/gui/app_status_manager.go b/pkg/gui/app_status_manager.go index 577dcb37d..431486ee9 100644 --- a/pkg/gui/app_status_manager.go +++ b/pkg/gui/app_status_manager.go @@ -58,7 +58,9 @@ func (gui *Gui) WithWaitingStatus(name string, f func() error) error { }() go func() { - for range time.Tick(time.Millisecond * 50) { + ticker := time.NewTicker(time.Millisecond * 50) + defer ticker.Stop() + for range ticker.C { appStatus := gui.statusManager.getStatusString() gui.Log.Warn(appStatus) if appStatus == "" { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index c419f5dc9..d735b8418 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -788,9 +788,11 @@ func (gui *Gui) renderGlobalOptions() error { func (gui *Gui) goEvery(interval time.Duration, stop chan struct{}, function func() error) { go func() { + ticker := time.NewTicker(interval) + defer ticker.Stop() for { select { - case <-time.Tick(interval): + case <-ticker.C: _ = function() case <-stop: return diff --git a/pkg/tasks/tasks.go b/pkg/tasks/tasks.go index 2468ac958..e062b6181 100644 --- a/pkg/tasks/tasks.go +++ b/pkg/tasks/tasks.go @@ -78,8 +78,10 @@ func (m *ViewBufferManager) NewCmdTask(cmd *exec.Cmd, linesToRead int) func(chan loaded := false go func() { + ticker := time.NewTicker(time.Millisecond * 100) + defer ticker.Stop() select { - case <-time.Tick(time.Millisecond * 100): + case <-ticker.C: if !loaded { m.beforeStart() m.writer.Write([]byte("loading...")) -- cgit v1.2.3