Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Jul 10, 2023
1 parent 6de1e43 commit 2161a8e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
go utils.Safe(func() {
isViewStale := true
writeToView := func(content []byte) {
_, _ = self.writer.Write(content)
isViewStale = true
_, _ = self.writer.Write(content)
}
refreshViewIfStale := func() {
if isViewStale {
Expand Down Expand Up @@ -299,18 +299,18 @@ type TaskOpts struct {
}

func (self *ViewBufferManager) NewTask(f func(TaskOpts) error, key string) error {
task := self.newGocuiTask()
gocuiTask := self.newGocuiTask()

var completeTaskOnce sync.Once

completeTask := func() {
completeGocuiTask := func() {
completeTaskOnce.Do(func() {
task.Done()
gocuiTask.Done()
})
}

go utils.Safe(func() {
defer completeTask()
defer completeGocuiTask()

self.taskIDMutex.Lock()
self.newTaskID++
Expand Down Expand Up @@ -350,7 +350,7 @@ func (self *ViewBufferManager) NewTask(f func(TaskOpts) error, key string) error

self.waitingMutex.Unlock()

if err := f(TaskOpts{Stop: stop, InitialContentLoaded: completeTask}); err != nil {
if err := f(TaskOpts{Stop: stop, InitialContentLoaded: completeGocuiTask}); err != nil {
self.Log.Error(err) // might need an onError callback
}

Expand Down

0 comments on commit 2161a8e

Please sign in to comment.