-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use init() for DefaultEntropy() instead of sync.Once #122
Comments
Where do you see sync.Once? defaultEntropy is defined here. |
in the master https://github.com/oklog/ulid/blob/main/ulid.go#L132 you are passing function definition to where you expect io.Reader, so you need to pass |
actually, i overlooked line 138. so now it looks better, though now it looks like the entropy source is generated during compilation time and is fixed, which is never good. |
defaultEntropy is just that, the default source of entropy for the package. It's constructed and assigned by the in-line function defined and evaluated between lines 135 and 138 -- which is just an alternative way of computing and assigning a value to a package global variable, versus doing the same work in a If you don't want to use the package global default entropy source, you don't have to. You just define whatever entropy source you want, and then pass that entropy source to (different) ULID constructors, to construct your ULIDs. This is fine. We can probably make a new release that reflects the current main, which lags the most recent release. |
sync.Once uses atomic load for each call. This makes little sense when entropy should be established once via init().
The text was updated successfully, but these errors were encountered: