Skip to content

Commit

Permalink
fix: snowflake generation
Browse files Browse the repository at this point in the history
  • Loading branch information
okkdev authored and rvcas committed Jun 4, 2024
1 parent 0b8ca6f commit 3f95ec7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ids/snowflake.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ fn update_state(state: State) -> State {
erlang.system_time(erlang.Millisecond)
|> int.subtract(state.epoch)

case state.last_time {
lt if lt == now && state.idx < 4095 -> State(..state, idx: state.idx + 1)
lt if lt == now -> update_state(state)
_other -> State(..state, last_time: now)
case state {
State(last_time: lt, idx: idx, ..) if lt == now && idx < 4095 -> {
State(..state, idx: state.idx + 1)
}
State(last_time: lt, ..) if lt == now -> update_state(state)
_other -> State(..state, last_time: now, idx: 0)
}
}

0 comments on commit 3f95ec7

Please sign in to comment.