Skip to content

Instantly share code, notes, and snippets.

@tomodutch
Last active February 11, 2016 09:49
Show Gist options
  • Select an option

  • Save tomodutch/186eb803720d21744b77 to your computer and use it in GitHub Desktop.

Select an option

Save tomodutch/186eb803720d21744b77 to your computer and use it in GitHub Desktop.
defmodule UID.Registry do
@moduledoc """
"""
use GenServer
@doc """
Link the Registry with the current process.
"""
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, 1, opts)
end
@doc ~S"""
Generate a new unique identifier starting at 1.
## Examples
iex> {:ok, pid} = UID.Registry.start_link
...> UID.Registry.generate_uid(pid)
1
"""
def generate_uid(pid) do
GenServer.call(pid, :get_uid)
end
def handle_call(:get_uid, _from, state) do
{:reply, state, state + 1}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment