Skip to content

Instantly share code, notes, and snippets.

@pap
Created August 11, 2014 13:23
Show Gist options
  • Select an option

  • Save pap/311b178691c808b9abb3 to your computer and use it in GitHub Desktop.

Select an option

Save pap/311b178691c808b9abb3 to your computer and use it in GitHub Desktop.
ETS table wrapper module
defmodule ConnectionTable do
@table_id __MODULE__
def init do
:ets.new(@table_id, [:public, :named_table])
end
def insert(key, value) do
:ets.insert(@table_id, {key, value})
end
def lookup(key) do
case :ets.lookup(@table_id, key) do
[{_key, value}] -> {:ok, value}
[] -> {:error, :not_found}
end
end
def delete(key) do
:ets.match_delete(@table_id, {key, :_})
end
def update(key, value) do
insert(key, value)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment