☎️ ERLANG HIVE DIFFICULTY: Adept Behavioral

The Mediator of the Hive Switchboard

A central switchboard process that routes all telepathy.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Mediator
ARCANUM SCHOOL: Enchantment // Networking
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ERLANG PATTERN //
-module(the_mediator).
-export([start_link/0, register_node/2, broadcast/2]).

start_link() -> spawn(fun() -> loop([]) end).

register_node(Broker, Pid) -> Broker ! {register, Pid}.
broadcast(Broker, Msg) -> Broker ! {broadcast, Msg}.

loop(Nodes) ->
    receive
        {register, Pid} -> loop([Pid | Nodes]);
        {broadcast, Msg} ->
            lists:foreach(fun(Node) -> Node ! Msg end, Nodes),
            loop(Nodes)
    end.

The Mediator

The heart of the Hive. A central broker that tracks all spirits and duplicates psychic messages across the void.

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