RobThree / IdGen

Twitter Snowflake-alike ID generator for .Net
MIT License
1.19k stars 148 forks source link

Timestamp bits go ahead of time #13

Closed dmitry-chistyakov closed 5 years ago

dmitry-chistyakov commented 5 years ago

DefaultTimeSource implementation uses static Stopwatch which starts on first usage of the class. If you instantiate DefaultTimeSource later (as part of new IdGenerator for example) it counts ticks as current offset + elapsed time on static Stopwatch which may run for awhile. As a result timestamp bits show time in future. It may result non-unique identifiers in some scenarios.

RobThree commented 5 years ago

The idea is that you use and timesource and stick with it; similarly, you don't want to use different timesources each time your application is run. However, that could be documented a bit more clearly, I agree.

RobThree commented 5 years ago

@dmitry-chistyakov Reading your question / issue again I'm not quite sure I understand correctly. Could you elaborate / provide an example maybe?

RobThree commented 5 years ago

Closing because of no input / feedback