Kent Rancourt
Oct 1, 2022

--

Your first example has a few issues...

The first is that , contextually, the race doesn't matter. All callers are racing to assign the same value to v. It still looks bad, so you're right to want to fix it...

sync.Once might be more than you need, however. You could set the value of v in init() and then there will never be any issue.

--

--

Kent Rancourt
Kent Rancourt

Written by Kent Rancourt

Kent is a founding engineer at Akuity, working primarily with Kubernetes, Argo CD, and other open source projects.

No responses yet