singleton
singleton copied to clipboard
Ability to execute custom start_link
https://github.com/arjan/singleton/blob/master/lib/singleton/manager.ex#L58
defp restart(state) do
start_result =
GenServer.start_link(state.mod, state.args, name: {:global, state.name})
pid =
case start_result do
{:ok, pid} ->
pid
{:error, {:already_started, pid}} ->
state.on_conflict && state.on_conflict.()
pid
end
Process.monitor(pid)
%State{state | pid: pid}
end
It would be nice if GenServer.start_link/3 here could be replaced by state.mod.start_link/3. That would allow for starting a process which depends on custom code within the start_link/3 function.