Elector - leader node election

Have you considered and/or compared this to making your singletons instead register globally and use the built in conflict resolution logic described in global?

Then you can use something like the following wrapper (inspiration from a decade old post) around your singletons in your supervisors to provide the resilience.

-module(singleton).

-export([start_link/3]).

start_link(M, F = start_link, A) ->
        case erlang:apply(M, F, A) of
                {ok, Pid} ->
                        {ok, Pid};
                {error,{already_started,Pid}} ->
                        link(Pid),
                        {ok, Pid};
                Else ->
                        Else
        end.

As a tip, it is always useful to others to include with your projects a description of why it exists and how the other strategies did not work for your situation(s) which is why you created this.

2 Likes