Skip to content

Commit

Permalink
rearrange
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwinchester committed Apr 22, 2024
1 parent 9716bb3 commit 6e56f56
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions lib/clock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,6 @@ defmodule UUIDv7.Clock do

@compile {:inline, [update_counter: 2]}

@doc """
Starts the Clock server.
### Options
* `:cleanup_interval` - The interval in milliseconds that the table cleanup
task is run. Defaults to `#{@default_cleanup_interval_ms}`.
* `:cleanup_tick_cutoff` - The number of timestamp ticks ago that the table
is pruned to. Defaults to `#{@default_cleanup_tick_cutoff}`.
"""
@spec start_link(keyword()) :: GenServer.on_start()
def start_link(opts) do
if Keyword.get(opts, :start?, true) do
name = Keyword.get(opts, :name) || __MODULE__
GenServer.start_link(__MODULE__, opts, name: name)
else
:ignore
end
end

@doc """
Get a unix millisecond timestamp and a clock sequence that fits in 18 bits.
"""
Expand Down Expand Up @@ -64,6 +43,30 @@ defmodule UUIDv7.Clock do
{current_ts, <<clock::big-unsigned-18>>}
end

@doc """
Starts the Clock server.
The GenServer part of this module is used for managing the ETS table and not
for generating UUIDs.
### Options
* `:cleanup_interval` - The interval in milliseconds that the table cleanup
task is run. Defaults to `#{@default_cleanup_interval_ms}`.
* `:cleanup_tick_cutoff` - The number of timestamp ticks ago that the table
is pruned to. Defaults to `#{@default_cleanup_tick_cutoff}`.
"""
@spec start_link(keyword()) :: GenServer.on_start()
def start_link(opts) do
if Keyword.get(opts, :start?, true) do
name = Keyword.get(opts, :name) || __MODULE__
GenServer.start_link(__MODULE__, opts, name: name)
else
:ignore
end
end

# ----------------------------------------------------------------------------
# GenServer callbacks.
# ----------------------------------------------------------------------------
Expand Down

0 comments on commit 6e56f56

Please sign in to comment.