sony / sonyflake

A distributed unique ID generator inspired by Twitter's Snowflake

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

i think the sleepTime func is wrong.

woshihuo12 opened this issue · comments

func sleepTime(overtime int64) time.Duration { return time.Duration(overtime)*10*time.Millisecond - time.Duration(time.Now().UTC().UnixNano()%sonyflakeTimeUnit)*time.Nanosecond }

i think overtime is no need minus the now time, so i think below is right:
func sleepTime(overtime int64) time.Duration { return time.Duration(overtime) * 10 * time.Millisecond }

i think overtime is no need minus the now time, so i think below is right:

The Now time is not subtracted in sleepTime.
Only the fraction against Sonyflake's unit time (10 msec) is subtracted in it:
time.Now().UTC().UnixNano()%sonyflakeTimeUnit