☎️ ERLANG HIVE DIFFICULTY: Adept Creational

The Singleton of the Hive Switchboard

The solitary eternal process, registered in the cosmic registry.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Anchoring
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ERLANG PATTERN //
-module(the_singleton).
-export([start/0, get_instance/0]).

start() ->
    case whereis(the_one) of
        undefined -> 
            Pid = spawn(fun loop/0),
            register(the_one, Pid),
            {ok, Pid};
        Pid -> {ok, Pid}
    end.

get_instance() -> whereis(the_one).

loop() -> receive _ -> loop() end.

The Singleton

A globally registered named process. The one true beacon in the chaotic void of the Hive Switchboard.

Runic Tags: #erlang #actors #telepathy #switchboard #singleton