How can I assign a name: to my GenServer in my start_link function. I’m using syn for process registry and via tuples doesn’t seem to work
Here’s my worker code from one micro library that I still have no clue what to do with:
o
@doc """
This is a `GenServer` that accepts a function with a single argument and executes it.
"""
use GenServer
# Server (callbacks)
@impl GenServer
def init(_state) do
{:ok, _state = []}
end
@impl GenServer
def handle_call({:run, fun, arg}, _from, _state = []) when is_function(fun, 1) do
{:reply, _return_value = fun.(arg), _state = []}
end
# Client
def child_spec(opts) do
name = Keyword.get(opts, :name, __MODULE__)
shutdown_timeout = Keyword.get(opts, :shutdown_timeout, 15_000)
%{
id: name,
restart: :permanent,
shutdown: shutdown_timeout,
start: {__MODULE__, :start_link, [name]},
type: :worker
}
end
def start_link(name) do
GenServer.start_link(__MODULE__, _state = [], name: name)
end
end
I am not seeing anything wrong just specifying name: :whatever
?
What have you tried?
I believe you’ll need to use:
name: {:via, :syn, {MyApp.Syn, id}}
2 Likes