func NewBackgroundSpinner()

in utils/spinner.go [26:59]


func NewBackgroundSpinner(description string, refresh time.Duration) context.CancelFunc {
	if refresh <= 0 {
		refresh = spinnerRefresh
	}

	ctx, cancel := context.WithCancel(context.Background())

	spinner := spin.New()
	spinner.Set(spin.Spin1)

	sync := make(chan bool)

	go func() {
		for {
			log.Errorf("\r%s... ", description)
			select {
			case <-ctx.Done():
				log.Errorf("Done.\n")
				sync <- false

				return
			default:
				log.Errorf("%s", spinner.Next())
			}
			time.Sleep(refresh)
		}
	}()

	return func() {
		// cancel context and wait for goroutine to clean the output
		cancel()
		<-sync
	}
}