From b1e5b3438306d82f590ce373546fe5a02c1563b5 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Thu, 24 Jun 2021 00:48:47 -0300 Subject: [PATCH] fix(clispinner): avoid data race (#1288) --- starport/pkg/clispinner/clispinner.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/starport/pkg/clispinner/clispinner.go b/starport/pkg/clispinner/clispinner.go index d50348a878..b28065265d 100644 --- a/starport/pkg/clispinner/clispinner.go +++ b/starport/pkg/clispinner/clispinner.go @@ -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 } @@ -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 }