diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-10 17:30:44 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-10 17:30:44 +1000 |
commit | d44d164a5a1b64f71696bdcb89c799d1d3179482 (patch) | |
tree | 028767212511da2a7540c90e745bbb816e93ba26 | |
parent | 90613056cef95fe32d19198d88a0d71f00c5f6ae (diff) |
Ensure background refreshes don't bunch up
-rw-r--r-- | pkg/gui/background.go | 8 |
1 files changed, 7 insertions, 1 deletions
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 } |