From d44d164a5a1b64f71696bdcb89c799d1d3179482 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 10 Jul 2023 17:30:44 +1000 Subject: [PATCH] Ensure background refreshes don't bunch up --- pkg/gui/background.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/gui/background.go b/pkg/gui/background.go index d8976549f..342e3127e 100644 --- a/pkg/gui/background.go +++ b/pkg/gui/background.go @@ -77,6 +77,7 @@ func (self *BackgroundRoutineMgr) startBackgroundFilesRefresh(refreshInterval in } func (self *BackgroundRoutineMgr) goEvery(interval time.Duration, stop chan struct{}, function func() error) { + done := make(chan struct{}) go utils.Safe(func() { ticker := time.NewTicker(interval) defer ticker.Stop() @@ -86,7 +87,12 @@ func (self *BackgroundRoutineMgr) goEvery(interval time.Duration, stop chan stru if self.pauseBackgroundRefreshes { continue } - self.gui.c.OnWorker(func(gocui.Task) { _ = function() }) + self.gui.c.OnWorker(func(gocui.Task) { + _ = function() + done <- struct{}{} + }) + // waiting so that we don't bunch up refreshes if the refresh takes longer than the interval + <-done case <-stop: return }