Supervision Trees — std.supervisor


Overview

std.supervisor provides Erlang-inspired supervision strategies for Eta actor processes. It composes directly with the existing actor primitives (spawn, monitor, recv!, send!, nng-poll, spawn-kill) and adds no new runtime machinery — just a structured event loop.

Two strategies ship out of the box:

StrategyRestart policy
one-for-oneOnly the crashed child is restarted
one-for-allAny crash kills all siblings and restarts the whole group

Both functions run a polling loop and do not return normally.

(import std.supervisor)

Note

The supervisor itself must be a spawned child (so it has a mailbox). Calling it on the main process would block the VM on recv!. Alternatively the included poll loop uses a 500 ms timeout so the supervisor can interleave with other periodic work.


API

(one-for-one children-specs)

(one-for-one '("worker-a.eta" "worker-b.eta" "worker-c.eta"))

(one-for-all children-specs)

(one-for-all '("ingester.eta" "worker.eta" "publisher.eta"))

Implementation Sketch

spawn each child           ─► monitor each child
        │                            │
        ▼                            ▼
   poll loop  ◄──── nng-poll(socks, 500ms) ────┐
        │                                       │
        ▼                                       │
   (down ...)?  ──no──► continue ───────────────┘

        yes

   one-for-one : respawn dead slot, re-monitor
   one-for-all : kill-all, start-all

The supervisor stores child sockets in a vector for stable index-based restart. nng-poll with a short timeout keeps the loop responsive without busy-waiting.


Composition Patterns


Source Locations

ComponentFile
std.supervisor modulestdlib/std/supervisor.eta
Actor primitivesstdlib/std/net.eta, Networking
Message-passing modelMessage Passing