func()

in unison/taskgroup.go [153:189]


func (t *TaskGroup) Go(fn func(context.Context) error) error {
	t.init(context.Background())

	if err := t.wg.Add(1); err != nil {
		return err
	}

	go func() {
		defer t.wg.Done()

		for t.closer.Err() == nil {
			err := fn(t.closer)
			action, err := t.OnQuit(err)

			if err != nil && err != context.Canceled {
				t.mu.Lock()
				t.errs = append(t.errs, err)
				if t.MaxErrors > 0 && len(t.errs) > t.MaxErrors {
					t.errs = t.errs[1:]
				}
				t.mu.Unlock()
			}

			switch action {
			case TaskGroupStopActionContinue:
				return // finish managed go-routine, but keep other routines alive.
			case TaskGroupStopActionShutdown:
				t.signalStop()
				return
			case TaskGroupStopActionRestart:
				// continue with loop
			}
		}
	}()

	return nil
}