summaryrefslogtreecommitdiffstats
path: root/pkg/gui/types
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-09 11:32:27 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-09 21:30:19 +1000
commit14ecc15e71f648a95dab297ce9360d0badb6669a (patch)
tree8a60cc5a3e9836688e6e1943266541a76628b141 /pkg/gui/types
parent9e79ee5fe36dc849479ce8f3b05e7cca56c7c216 (diff)
Use first class task objects instead of global counter
The global counter approach is easy to understand but it's brittle and depends on implicit behaviour that is not very discoverable. With a global counter, if any goroutine accidentally decrements the counter twice, we'll think lazygit is idle when it's actually busy. Likewise if a goroutine accidentally increments the counter twice we'll think lazygit is busy when it's actually idle. With the new approach we have a map of tasks where each task can either be busy or not. We create a new task and add it to the map when we spawn a worker goroutine (among other things) and we remove it once the task is done. The task can also be paused and continued for situations where we switch back and forth between running a program and asking for user input. In order for this to work with `git push` (and other commands that require credentials) we need to obtain the task from gocui when we create the worker goroutine, and then pass it along to the commands package to pause/continue the task as required. This is MUCH more discoverable than the old approach which just decremented and incremented the global counter from within the commands package, but it's at the cost of expanding some function signatures (arguably a good thing). Likewise, whenever you want to call WithWaitingStatus or WithLoaderPanel the callback will now have access to the task for pausing/ continuing. We only need to actually make use of this functionality in a couple of places so it's a high price to pay, but I don't know if I want to introduce a WithWaitingStatusTask and WithLoaderPanelTask function (open to suggestions).
Diffstat (limited to 'pkg/gui/types')
-rw-r--r--pkg/gui/types/common.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go
index e526e3d0d..372cd1629 100644
--- a/pkg/gui/types/common.go
+++ b/pkg/gui/types/common.go
@@ -79,7 +79,7 @@ type IGuiCommon interface {
OnUIThread(f func() error)
// Runs a function in a goroutine. Use this whenever you want to run a goroutine and keep track of the fact
// that lazygit is still busy. See docs/dev/Busy.md
- OnWorker(f func())
+ OnWorker(f func(*gocui.Task))
// returns the gocui Gui struct. There is a good chance you don't actually want to use
// this struct and instead want to use another method above
@@ -121,8 +121,8 @@ type IPopupHandler interface {
Confirm(opts ConfirmOpts) error
// Shows a popup prompting the user for input.
Prompt(opts PromptOpts) error
- WithLoaderPanel(message string, f func() error) error
- WithWaitingStatus(message string, f func() error) error
+ WithLoaderPanel(message string, f func(*gocui.Task) error) error
+ WithWaitingStatus(message string, f func(*gocui.Task) error) error
Menu(opts CreateMenuOptions) error
Toast(message string)
GetPromptInput() string