MCPcopy
hub / github.com/jesseduffield/lazygit / NewTask

Method NewTask

pkg/tasks/tasks.go:373–435  ·  view source on GitHub ↗
(f func(TaskOpts) error, key string)

Source from the content-addressed store, hash-verified

371}
372
373func (self *ViewBufferManager) NewTask(f func(TaskOpts) error, key string) error {
374 gocuiTask := self.newGocuiTask()
375
376 var completeTaskOnce sync.Once
377
378 completeGocuiTask := func() {
379 completeTaskOnce.Do(func() {
380 gocuiTask.Done()
381 })
382 }
383
384 go utils.Safe(func() {
385 defer completeGocuiTask()
386
387 self.taskIDMutex.Lock()
388 self.newTaskID++
389 taskID := self.newTaskID
390
391 if self.GetTaskKey() != key && self.onNewKey != nil {
392 self.onNewKey()
393 }
394 self.taskKey = key
395
396 self.taskIDMutex.Unlock()
397
398 self.waitingMutex.Lock()
399
400 self.taskIDMutex.Lock()
401 if taskID < self.newTaskID {
402 self.waitingMutex.Unlock()
403 self.taskIDMutex.Unlock()
404 return
405 }
406 self.taskIDMutex.Unlock()
407
408 if self.stopCurrentTask != nil {
409 self.stopCurrentTask()
410 }
411
412 self.readLines = nil
413
414 stop := make(chan struct{})
415 notifyStopped := make(chan struct{})
416
417 var once sync.Once
418 onStop := func() {
419 close(stop)
420 <-notifyStopped
421 }
422
423 self.stopCurrentTask = func() { once.Do(onStop) }
424
425 self.waitingMutex.Unlock()
426
427 if err := f(TaskOpts{Stop: stop, InitialContentLoaded: completeGocuiTask}); err != nil {
428 self.Log.Error(err) // might need an onError callback
429 }
430

Callers

nothing calls this directly

Calls 5

GetTaskKeyMethod · 0.95
SafeFunction · 0.92
DoMethod · 0.80
DoneMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected