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