Race condition on New Spinner - allow WaitGroup?
Closed this issue · 6 comments
Hi,
My go tests encounter a data race when executing this simple block of code
s := spinner.New(spinner.CharSets[14], 150*time.Millisecond)
s.Color("blue")
s.Writer = os.Stderr
The race occurs between the s.Writer = os.Stderr
and https://github.com/briandowns/spinner/blob/master/spinner.go#L298
I'm wondering if we can add a WaitGroup somehow so I can wait for the spinner.New() go routine to be finished.
Thank you for reporting this. What version are you running?
using v1.8.0
. Another solution I was thinking of is if we can pass a writer to spinner.New()
to initialize with?
Essentially we just need an API for changing the writer because the race condition is triggered by the goroutine.
I've added an additional option function in #90 to allow for setting a new writer as well as updated the doc comments and readme to indicate this is the preferred method for now. I decided not to change the package API in any way at this time as I believe it should warrant a 2.0 marker for such a change and I'm avoid that at all costs to save all of the users from having to update their import strings because... go mods.
thanks! I'll test this out once merged and let you know if it resolves my issue
Checkout release v1.10.0