Rounding time to nearest millisecond

This commit is contained in:
Nishaad Ajani 2019-04-03 14:23:35 +08:00 committed by GitHub
parent af41c88b24
commit 0685b6ac31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,14 +108,14 @@ func (n *Node) Generate() ID {
n.mu.Lock() n.mu.Lock()
now := time.Now() now := time.Now().Round(time.Millisecond)
if now.Sub(n.time) < time.Millisecond { if now.Sub(n.time) < time.Millisecond {
n.step = (n.step + 1) & stepMask n.step = (n.step + 1) & stepMask
if n.step == 0 { if n.step == 0 {
for now.Sub(n.time) < time.Millisecond { for now.Sub(n.time) < time.Millisecond {
now = time.Now() now = time.Now().Round(time.Millisecond)
} }
} }
} else { } else {