Skip to content

Instantly share code, notes, and snippets.

@josefrichter
Created June 1, 2020 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josefrichter/369df63eded8a5b8285622db572dace2 to your computer and use it in GitHub Desktop.
Save josefrichter/369df63eded8a5b8285622db572dace2 to your computer and use it in GitHub Desktop.
defmodule KV.Registry do
use GenServer
## Missing Client API - will add this later
## Defining GenServer Callbacks
@impl true
def init(:ok) do
{:ok, %{}}
end
@impl true
def handle_call({:lookup, name}, _from, names) do
{:reply, Map.fetch(names, name), names}
end
@impl true
def handle_cast({:create, name}, names) do
if Map.has_key?(names, name) do
{:noreply, names}
else
{:ok, bucket} = KV.Bucket.start_link([])
{:noreply, Map.put(names, name, bucket)}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment