Initial Commit
This commit is contained in:
17
kv.exs
Normal file
17
kv.exs
Normal file
@@ -0,0 +1,17 @@
|
||||
# Key-Value store
|
||||
defmodule KV do
|
||||
def start_link do
|
||||
Task.start_link(fn -> loop(%{}) end)
|
||||
end
|
||||
|
||||
defp loop(map) do
|
||||
receive do
|
||||
{:get, key, caller} ->
|
||||
send(caller, Map.get(map, key))
|
||||
loop(map)
|
||||
{:put, key, value} ->
|
||||
loop(Map.put(map, key, value))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user