Closed bysir-zl closed 5 years ago
In line 141: if now == n.time {, I think it has a little problem:
if now == n.time {
If the time on the machine falls back(now<n.time), duplicate IDS will be generated.
The right way should be like sonyflke (https://github.com/sony/sonyflake/blob/master/sonyflake.go#L96)
This project has the most stars on github. I hope it's perfect. Haha.
Maybe take a look at the details in this PR :)
https://github.com/bwmarrin/snowflake/pull/18
In Go, 1.9 and later, time package uses a monotonic clock for time-measuring operations.
In line 141:
if now == n.time {
, I think it has a little problem:If the time on the machine falls back(now<n.time), duplicate IDS will be generated.
The right way should be like sonyflke (https://github.com/sony/sonyflake/blob/master/sonyflake.go#L96)
This project has the most stars on github. I hope it's perfect. Haha.