☎️ ERLANG HIVE DIFFICULTY: Adept Behavioral

The State of the Hive Switchboard

Finite state machines mapped directly to process behavior.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Phase
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ERLANG PATTERN //
-module(the_state).
-export([start/0, idle/1, active/1]).

start() -> spawn(fun() -> idle(#{}) end).

idle(Data) ->
    receive
        wake -> active(Data)
    end.

active(Data) ->
    receive
        sleep -> idle(Data)
    end.

The State

In Erlang, the State pattern is the lifeblood of gen_statem. A process transitions between phases of existence simply by calling a different function.

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