snowflakes

package
v0.0.0-...-22d4692 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2017 License: MIT, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	StartTime int64
	// contains filtered or unexported fields
}

Generator is a fountain for new snowflakes. StartTime must be initialized to a past point in time and Instance ID can be any positive value or 0.

If any value is not correctly set, new IDs cannot be produced.

func (*Generator) IDToUnix

func (g *Generator) IDToUnix(id int) int

func (*Generator) NewID

func (g *Generator) NewID() (int64, error)

NewID generates a new, unique snowflake value

Up to 8192 snowflakes per second can be requested If exhausted, it blocks and sleeps until a new second of unix time starts.

The return value is signed but always positive.

Additionally, the return value is monotonic for a single instance and weakly monotonic for many instances.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL