View Source Pika.Snowflake (pika v0.3.0)
Pika.Snowflake
holds the state, generates Snowflakes, and decodes Snowflakes.
Pika.Snowflake
should be started under a Supervisor
or Application
before you start using
Pika.gen/1
or Pika.deconstruct/1
defmodule MyApp.Application do
use Application
def start(_type, _args) do
children = [Pika.Snowflake]
Supervisor.start_link(children, strategy: :one_for_one)
end
end
or manually in iex
iex(1)> Pika.Snowflake.start_link()
{:ok, #PID<0.190.0>}
Custom epoch
You can start Pika.Snowflake
with a custom epoch by passing it:
Pika.Snowflake.start_link(1_650_153_600_000)
Summary
Functions
Returns a specification to start this module under a supervisor.
Decodes a Snowflake and returns
Generates a new Snowflake
Generates a new Snowflake with the given timestamp
Callback implementation for GenServer.init/1
.
Returns the current timestamp in milliseconds.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Decodes a Snowflake and returns:
- timestamp
- epoch
- node_id
- seq
@spec generate() :: integer()
Generates a new Snowflake
Generates a new Snowflake with the given timestamp
Callback implementation for GenServer.init/1
.
Returns the current timestamp in milliseconds.