Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple GenServer callback to create a map w/ {key, value} pairs by looking at the filesystem
@impl GenServer
def handle_call({:all}, _timeout, _state) do
{:ok, files} = :file.list_dir(@database)
state =
Enum.map(files, fn (key) ->
value =
case File.read(file_name(@database, key)) do
{:ok, contents} -> :erlang.binary_to_term(contents)
_ -> nil
end
{key, value}
end)
|> Enum.into(%{})
{:reply, state, state}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.