From 0685b6ac316158085ce9cc22c3d8f076b80a7d15 Mon Sep 17 00:00:00 2001 From: Nishaad Ajani Date: Wed, 3 Apr 2019 14:23:35 +0800 Subject: [PATCH] Rounding time to nearest millisecond --- snowflake.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snowflake.go b/snowflake.go index 8d17e10..c4efceb 100644 --- a/snowflake.go +++ b/snowflake.go @@ -108,14 +108,14 @@ func (n *Node) Generate() ID { n.mu.Lock() - now := time.Now() + now := time.Now().Round(time.Millisecond) if now.Sub(n.time) < time.Millisecond { n.step = (n.step + 1) & stepMask if n.step == 0 { for now.Sub(n.time) < time.Millisecond { - now = time.Now() + now = time.Now().Round(time.Millisecond) } } } else {