diff --git a/flake.go b/flake.go index bb0e5ed..9001032 100644 --- a/flake.go +++ b/flake.go @@ -70,6 +70,7 @@ func (n *Node) Generator(c chan Flake) { if n.step == 0 { // wait for ticker.. + // haha, funny, this isn't fast enough to ever get here. } case <-ticker.C: now++ @@ -141,6 +142,58 @@ func (n *Node) Generate() (Flake, error) { ), nil } +// Return a freshly generated Flake ID +func (n *Node) GenerateNoSleep() (Flake, error) { + + now := time.Now().UnixNano() / 1000000 + + if n.lastTime == now { + n.step = (n.step + 1) & StepMask + + if n.step == 0 { + for now <= n.lastTime { + now = time.Now().UnixNano() / 1000000 + } + } + } else { + n.step = 0 + } + + n.lastTime = now + + return Flake((now-n.epoch)<