Created
June 1, 2020 20:28
-
-
Save josefrichter/369df63eded8a5b8285622db572dace2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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