Skip to content

Commit

Permalink
fix(clispinner): avoid data race (#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored Jun 24, 2021
1 parent 7c706c7 commit b1e5b34
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions starport/pkg/clispinner/clispinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ func New() *Spinner {
s := &Spinner{
sp: sp,
}
s.SetText("Initializing...")
return s
return s.SetText("Initializing...")
}

// SetText sets the text for spinner.
func (s *Spinner) SetText(text string) *Spinner {
s.sp.Lock()
s.sp.Suffix = " " + text
s.sp.Unlock()
return s
}

// SetPrefix sets the prefix for spinner.
func (s *Spinner) SetPrefix(text string) *Spinner {
s.sp.Lock()
s.sp.Prefix = text + " "
s.sp.Unlock()
return s
}

Expand All @@ -60,9 +63,9 @@ func (s *Spinner) Start() *Spinner {
// Stop stops spinning.
func (s *Spinner) Stop() *Spinner {
s.sp.Stop()
s.SetColor(spinnerColor)
s.SetPrefix("")
s.SetCharset(charset)
s.sp.Prefix = ""
s.sp.Color(spinnerColor)
s.sp.UpdateCharSet(charset)
s.sp.Stop()
return s
}

0 comments on commit b1e5b34

Please sign in to comment.