mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Use readLines channel only for command tasks
And only while the task is running. This avoids accumulating lots of blocked goroutines when scrolling a view down more than 1024 times (the capacity of the readLines channel).
This commit is contained in:
parent
7b17f33e9e
commit
60887eddd0
1 changed files with 10 additions and 5 deletions
|
@ -91,16 +91,18 @@ func NewViewBufferManager(
|
|||
beforeStart: beforeStart,
|
||||
refreshView: refreshView,
|
||||
onEndOfInput: onEndOfInput,
|
||||
readLines: make(chan LinesToRead, 1024),
|
||||
readLines: nil,
|
||||
onNewKey: onNewKey,
|
||||
newGocuiTask: newGocuiTask,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *ViewBufferManager) ReadLines(n int) {
|
||||
go utils.Safe(func() {
|
||||
self.readLines <- LinesToRead{Total: n, InitialRefreshAfter: -1}
|
||||
})
|
||||
if self.readLines != nil {
|
||||
go utils.Safe(func() {
|
||||
self.readLines <- LinesToRead{Total: n, InitialRefreshAfter: -1}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), prefix string, linesToRead LinesToRead, onDoneFn func()) func(TaskOpts) error {
|
||||
|
@ -166,7 +168,6 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
|
|||
|
||||
loadingMutex := deadlock.Mutex{}
|
||||
|
||||
// not sure if it's the right move to redefine this or not
|
||||
self.readLines = make(chan LinesToRead, 1024)
|
||||
|
||||
scanner := bufio.NewScanner(r)
|
||||
|
@ -274,6 +275,8 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
|
|||
}
|
||||
}
|
||||
|
||||
self.readLines = nil
|
||||
|
||||
refreshViewIfStale()
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
|
@ -349,6 +352,8 @@ func (self *ViewBufferManager) NewTask(f func(TaskOpts) error, key string) error
|
|||
go utils.Safe(func() {
|
||||
defer completeGocuiTask()
|
||||
|
||||
self.readLines = nil
|
||||
|
||||
self.taskIDMutex.Lock()
|
||||
self.newTaskID++
|
||||
taskID := self.newTaskID
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue