mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
close goEvery goroutines when switching to a subprocess
This commit is contained in:
parent
54a8068bdd
commit
f34c7b9058
2 changed files with 15 additions and 1 deletions
|
|
@ -121,6 +121,11 @@ type guiState struct {
|
||||||
Panels *panelStates
|
Panels *panelStates
|
||||||
SubProcessOutput string
|
SubProcessOutput string
|
||||||
Stats map[string]commands.ContainerStats
|
Stats map[string]commands.ContainerStats
|
||||||
|
|
||||||
|
// SessionIndex tells us how many times we've come back from a subprocess.
|
||||||
|
// We increment it each time we switch to a new subprocess
|
||||||
|
// Every time we go to a subprocess we need to close a few goroutines so this index is used for that purpose
|
||||||
|
SessionIndex int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGui builds a new gui handler
|
// NewGui builds a new gui handler
|
||||||
|
|
@ -144,6 +149,7 @@ func NewGui(log *logrus.Entry, dockerCommand *commands.DockerCommand, oSCommand
|
||||||
},
|
},
|
||||||
Status: &statusState{ContextIndex: 0},
|
Status: &statusState{ContextIndex: 0},
|
||||||
},
|
},
|
||||||
|
SessionIndex: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
cyclableViews := []string{"status", "containers", "images", "volumes"}
|
cyclableViews := []string{"status", "containers", "images", "volumes"}
|
||||||
|
|
@ -230,9 +236,13 @@ func (gui *Gui) renderGlobalOptions() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) goEvery(interval time.Duration, function func() error) {
|
func (gui *Gui) goEvery(interval time.Duration, function func() error) {
|
||||||
|
currentSessionIndex := gui.State.SessionIndex
|
||||||
_ = function() // time.Tick doesn't run immediately so we'll do that here // TODO: maybe change
|
_ = function() // time.Tick doesn't run immediately so we'll do that here // TODO: maybe change
|
||||||
go func() {
|
go func() {
|
||||||
for range time.Tick(interval) {
|
for range time.Tick(interval) {
|
||||||
|
if gui.State.SessionIndex > currentSessionIndex {
|
||||||
|
return
|
||||||
|
}
|
||||||
_ = function()
|
_ = function()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,15 @@ func (gui *Gui) RunWithSubprocesses() error {
|
||||||
} else if err == gui.Errors.ErrSubProcess {
|
} else if err == gui.Errors.ErrSubProcess {
|
||||||
// preparing the state for when we return
|
// preparing the state for when we return
|
||||||
gui.State.PreviousView = gui.currentViewName()
|
gui.State.PreviousView = gui.currentViewName()
|
||||||
gui.State.Panels.Main.ObjectKey = ""
|
// giving goEvery goroutines time to finish
|
||||||
|
gui.State.SessionIndex++
|
||||||
|
|
||||||
if err := gui.runCommand(); err != nil {
|
if err := gui.runCommand(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensuring we render e.g. the logs of the currently selected item upon return
|
||||||
|
gui.State.Panels.Main.ObjectKey = ""
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue