-
Notifications
You must be signed in to change notification settings - Fork 4
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
Provide true monotonicity guarantee #2
Comments
I'm not sure about this change. I decided to implement it the way it's done right now because it takes away the responsibility of thread-safety from this crate and puts the burden on the user. Not because I'm lazy or afraid of implementing it, but because it's use-case-specific what kind of monotonicity is required/desired. So if you call the I ultimately implemented it like this because of separation of concerns and the current Rust restraint that it's impossible (to my knowledge) to write code receiving either a Please don't consider this as a strict "no" from my side. I just wanted to explain the rationale for the current implementation. |
I understand your point. That's why I asked. Perhaps the middle ground is to fix the existing monotonic implementation so that it does provide monotonicity guarantees, but leaves the multi-threading as an exercise for the user. |
@rrichardson
You'd use them in your own use-case specific implementation like this: fn postprocessor_fn(ulid: Ulid) -> Ulid {
// zero out lowest 32 bits
Ulid::from(u128::from(ulid) & 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_0000_0000)
}
let previous_ulid = /* obtained from somewhere unspecified */;
let ulid = Ulid::next_strictly_monotonic_from_timestamp_with_rng_and_postprocessor(
Some(previous_ulid),
timestamp,
&mut rand::thread_rng(),
Some(&postprocessor_fn),
); Hope this helps. |
Thanks for creating such a great utility. I love how well organized and especially well documented it is.
Would there be interest in an API for this which provides a next_monotonic but does so using a thread-safe context and the value is updated atomically? I understand that this might be a major departure from the scope of this crate, which is why I'm asking. I'm happy to make the enhancements, but only if you are interested in such a scope change/increase.
If so, here's my thoughts:
Multiple ULIDs per millisecond not guaranteed ulid/spec#11
This isn't correct code, and I'm sure the algo could be made to be safer and more efficient.
That's the basic idea, though.
It would be a bit slower than the non-threaded version, but, that is usually the case.
Edit : Man I really typo'd the crap out of this post. I need to get more sleep
The text was updated successfully, but these errors were encountered: