Skip to content

Ability to execute custom start_link #12

Description

@stocks29

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions