diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-01 12:23:56 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-02 11:26:24 +1100 |
commit | df050472a1330dbaed8e4e85571db3300143f827 (patch) | |
tree | 92b8fa522bf302736324e9119efbd4717c137086 /pkg | |
parent | c173ebf5b9b4c691e176ba8956aabada7b1b3562 (diff) |
more ticker improvements
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/app_status_manager.go | 4 | ||||
-rw-r--r-- | pkg/gui/gui.go | 4 | ||||
-rw-r--r-- | pkg/tasks/tasks.go | 4 |
3 files changed, 9 insertions, 3 deletions
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...")) |