Closed whwright closed 6 years ago
Thinking about this some more over the last day: I'm leaning towards a new API like GenerateId()
that reuses the Generate()
logic with the added functionality of returning an error. This seems to solve both problems.
I can get a PR up for this shortly, but I'm still interested in your feedback.
Let me think about it :) I'd really like to avoid changing the API at this point.
Maybe if it detects a clock drift, it could wait until time catches up?
I'm curious what an example of how we'd check for drift would look too
I'll get a PR up and we can go from there.
We did this in our fork here https://github.com/blacklocus/snowflake. I'm going to close this.
I understand :) I think eventually I'll try to get this or a similar solution added to the library here as well. I just haven't had time to work on it in the last few months :(. Hopefully I catch up!
@whwright the current implementation now uses monotonic clock to safeguard against wall clock backwards movement. Ref: #18
Thanks for the ping @nishaad78; I didn't know about the monotonic clock implementation in go. This is a great way to solve the problem! 🎉
The current implementation does not check for clock drift when generating snowflakes. This would be fairly easy to implement a basic check, however I think the cleanest way would be to change the
Generate()
function signature to return anerror
as well.I understand this is a breaking API change you may not want. I am wondering if you are open to this change in any form. This could be breaking the API, deploying versioned packages with something like gopkg.in, creating a new API, etc...
Let me know what you think.