ids/snowflake
A module for generating Snowflake IDs.
Types
The messages handled by the actor. The actor shouldn’t be called directly so this type is opaque.
pub opaque type Message
Functions
pub fn decode(snowflake: Int) -> Result(#(Int, Int, Int), String)
Decodes a Snowflake ID into #(timestamp, machine_id, idx).
pub fn generate(channel: Subject(Message)) -> Int
Generates a Snowflake ID using the given channel.
Usage
import ids/snowflake
let assert Ok(channel) = snowflake.start(machine_id: 1)
let id: Int = snowflake.generate(channel)
let discord_epoch = 1_420_070_400_000
let assert Ok(d_channel) = snowflake.start_with_epoch(machine_id: 1, epoch: discord_epoch)
let discord_id: Int = snowflake.generate(d_channel)
pub fn start(machine_id: Int) -> Result(Subject(Message), String)
Starts a Snowflake generator.
pub fn start_with_epoch(
machine_id: Int,
epoch: Int,
) -> Result(Subject(Message), String)
Starts a Snowflake generator with an epoch offset.