In a GenServer
def init(_opts \\ []) do
table = :ets.new(:my_table, [:duplicate_bag, :public])
{:ok, %{}}
end
def add_player(zone_id, socket_id) do
:ets.thing(
:my_table,
{some_key, [my_uuid]}
)
end
But I get the table identifier does not refer to an existing ETS table
It's a public table, and I know init is getting called before the test executes because I logged in there.
I'm not sure why ets is doing this.
In order to reference the table by its name, you need to make it a named table when creating it:
Without
:named_table, you need to use the reference returned by:ets.newto access the table.(Also note that the table will be deleted if the process that created it dies, but that doesn't seem to be what's happening here.)