Skip to content

Commit b13fe8d

Browse files
committed
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).
1 parent 76f1959 commit b13fe8d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pkg/tasks/tasks.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,18 @@ func NewViewBufferManager(
9191
beforeStart: beforeStart,
9292
refreshView: refreshView,
9393
onEndOfInput: onEndOfInput,
94-
readLines: make(chan LinesToRead, 1024),
94+
readLines: nil,
9595
onNewKey: onNewKey,
9696
newGocuiTask: newGocuiTask,
9797
}
9898
}
9999

100100
func (self *ViewBufferManager) ReadLines(n int) {
101-
go utils.Safe(func() {
102-
self.readLines <- LinesToRead{Total: n, InitialRefreshAfter: -1}
103-
})
101+
if self.readLines != nil {
102+
go utils.Safe(func() {
103+
self.readLines <- LinesToRead{Total: n, InitialRefreshAfter: -1}
104+
})
105+
}
104106
}
105107

106108
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
166168

167169
loadingMutex := deadlock.Mutex{}
168170

169-
// not sure if it's the right move to redefine this or not
170171
self.readLines = make(chan LinesToRead, 1024)
171172

172173
scanner := bufio.NewScanner(r)
@@ -274,6 +275,8 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
274275
}
275276
}
276277

278+
self.readLines = nil
279+
277280
refreshViewIfStale()
278281

279282
if err := cmd.Wait(); err != nil {
@@ -349,6 +352,8 @@ func (self *ViewBufferManager) NewTask(f func(TaskOpts) error, key string) error
349352
go utils.Safe(func() {
350353
defer completeGocuiTask()
351354

355+
self.readLines = nil
356+
352357
self.taskIDMutex.Lock()
353358
self.newTaskID++
354359
taskID := self.newTaskID

0 commit comments

Comments
 (0)