I have defined a module GS
where genserver will be used and I need to create tables. I have the whole logic of the program In another module named base
. How do I inherit handle_call
in my genserver GS
module ?
GS MODULE:
defmodule GS do
use GenServer
@name gen
# client
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, [], opts ++ [name: gen])
end
def creating_tables(tables_list) do
GenServer.call(@name, {:creating_tables, tables_list})
end
# server
def init(initial_state) do
{:ok, initial_state}
end
end
BASE MODULE
defmodule Base do
def handle_call({:creating_tables}, _from, state_tables_list) do
tables = Enum.map(state_tables_list, fn table -> create(table) end)
{:reply, tables, state_tables_list}
end
defp create(table) do
try do
:ets.new(table, [:named_table, :bag])
rescue
ArgumentError -> table
end
end
end