by knorker · 7y ago · 0 comments
Just one comment though:
> Embedding sync.Mutex
Never do this on an exported type. If you embed sync.Mutex that makes "Lock" and "Unlock" part of your exported interface. Now the caller of your API doesn't know if they are supposed to call Lock/Unlock, or if this is a pure internal implementation detail.
your `type Stats` "isn't" a mutex. It has a mutex.
Isn't that exactly what they say?
> Embed for private types or types that need to implement the Mutex interface.
Personally, I would never embed a sync.Mutex though because even for an internal type it is confusing.
HashMap is probably a good example