Std. Supervisor
(Cure Standard Library v0.37.2)
View Source
The structured supervisor surface is source-defined, providing closed-vocabulary
restart, shutdown, child-type, and strategy constructors alongside the sup
and child_spec macros.
Examples
use Std.Supervisor
use Std.Nat
supervision_strategy(one_for_one(), S(S(S(Z()))), more(S(S(S(S(Z()))))))
child(:my_worker, :worker_1)
child_with(:my_worker, :worker_2, transient(), brutal_shutdown(), worker())
Summary
Functions
Shutdown policy: immediately terminate the child with :kill.
Build a default permanent worker ChildSpec with a 5000 ms shutdown timeout.
Build a ChildSpec with an atom child id, no start arguments, and explicit
restart, shutdown, and child_type policies.
The MFA argument list is polymorphic for direct homogeneous child specs. Heterogeneous supervisor lists still require the raw BEAM term boundary.
Build a ChildSpec with a pre-encoded RawTerm child identity and no start arguments.
Build a ChildSpec with an explicit list of erased RawTerm start arguments.
Build a ChildSpec by erasing each element of a homogeneous args list into
a RawTerm for the child's start_link MFA.
Return true if expected matches the constructor key of any syntax node in values.
Macro expander for sup: rejects duplicate child identities and otherwise
delegates to derive_verified_supervisor.
Expand child <module> id <identity> into Std.Supervisor.encoded_child
with a to_beam-encoded child identity.
Emit a verified OTP supervisor module AST containing ChildId, Handle,
init/1, start_link/0, start/0, and stop/2.
Return true if any two child definitions share the same constructor key.
Return an empty List(RawTerm) for child specs that take no start arguments.
Preferred typed-ID boundary. The caller resolves BeamEncode(id) and passes
the resulting opaque term here; macro expansion itself carries no hidden
dictionary argument. At runtime the term is the exact supervisor child ID.
Strictly positive period of n + 1 seconds.
Strictly positive period of 1 second.
Supervision strategy: restart all children when any child terminates.
Supervision strategy: restart only the terminated child.
Unwrap an optional syntax node, returning fallback when None.
Restart policy: always restart the child when it terminates.
Convert the closed strategy vocabulary to the ordinary supervisor tuple.
The strategy itself cannot be an arbitrary atom at a checked call site.
OTP permits zero restart intensity, but its restart period must be
strictly positive. Positive encodes that distinction without an
assertion or unchecked integer conversion.
Explicit raw-term child arguments for a heterogeneous BEAM MFA list.
Every element must cross raw_arg/1 at the call site; no typed value is
silently widened by this constructor.
Supervision strategy: restart the terminated child and all children started after it.
Shutdown policy: wait up to timeout milliseconds for graceful shutdown.
Build an OTP supervision strategy tuple {strategy, intensity, period} from
the closed Strategy vocabulary, restart intensity, and strictly positive period.
Child type marking a nested supervisor process.
Collect enum variant syntax nodes for each child identity in a sup block.
Translate a child kind keyword (supervisor, actor, or worker) into its
Std.Supervisor constructor call AST, failing on unknown kinds.
Lower each child definition in a sup block into a child_with_encoded call AST.
Convert an identifier syntax node into a nullary constructor call, leaving other syntax nodes unchanged.
Extract the :constructor_key atom attribute from a syntax node, if present.
Restart policy: never restart the child when it terminates.
Restart policy: restart the child only on abnormal termination.
Child type marking a supervised worker process.
Types
type ChildSpec
enum ChildType
Worker
Supervisor
enum Positive
One
More
enum Restart
Permanent
Temporary
Transient
enum Shutdown
Brutal
Timeout
enum Strategy
OneForOne
OneForAll
RestForOne
type StrategySpec
Functions
fn brutal_shutdown() -> Shutdown
Shutdown policy: immediately terminate the child with :kill.
fn child(module: Atom, id: Atom) -> ChildSpec
Build a default permanent worker ChildSpec with a 5000 ms shutdown timeout.
fn child_type_atom(child_type: ChildType) -> Atom
fn child_with(module: Atom, id: Atom, restart: Restart, shutdown: Shutdown, child_type: ChildType) -> ChildSpec
Build a ChildSpec with an atom child id, no start arguments, and explicit
restart, shutdown, and child_type policies.
fn child_with_args(a: Type, module: Atom, id: Atom, args: List(a), restart: Restart, shutdown: Shutdown, child_type: ChildType) -> Tuple(RawTerm, Tuple(Atom, Atom, List(a)), Atom, Nat, Atom, List(Atom))
The MFA argument list is polymorphic for direct homogeneous child specs. Heterogeneous supervisor lists still require the raw BEAM term boundary.
fn child_with_encoded(module: Atom, id: RawTerm, restart: Restart, shutdown: Shutdown, child_type: ChildType) -> ChildSpec
Build a ChildSpec with a pre-encoded RawTerm child identity and no start arguments.
fn child_with_raw_args(module: Atom, id: Atom, args: List(RawTerm), restart: Restart, shutdown: Shutdown, child_type: ChildType) -> ChildSpec
Build a ChildSpec with an explicit list of erased RawTerm start arguments.
fn child_with_typed_args(a: Type, module: Atom, id: Atom, args: List(a), restart: Restart, shutdown: Shutdown, child_type: ChildType) -> ChildSpec
Build a ChildSpec by erasing each element of a homogeneous args list into
a RawTerm for the child's start_link MFA.
fn contains_identity(values: List(Syntax), expected: Atom) -> Bool
Return true if expected matches the constructor key of any syntax node in values.
fn derive_supervisor_family(name: ModuleNameSyntax, definition: SupervisorDefinitionSyntax) -> Syntax
Macro expander for sup: rejects duplicate child identities and otherwise
delegates to derive_verified_supervisor.
fn derive_typed_child(module: ModuleNameSyntax, identity: Syntax) -> Syntax
Expand child <module> id <identity> into Std.Supervisor.encoded_child
with a to_beam-encoded child identity.
fn derive_verified_supervisor(name: ModuleNameSyntax, definition: SupervisorDefinitionSyntax) -> Syntax
Emit a verified OTP supervisor module AST containing ChildId, Handle,
init/1, start_link/0, start/0, and stop/2.
fn duplicate_child_identity(children: List(ChildDefinitionSyntax), found: List(Syntax)) -> Bool
Return true if any two child definitions share the same constructor key.
fn empty_raw_args() -> List(RawTerm)
Return an empty List(RawTerm) for child specs that take no start arguments.
fn encoded_child(module: Atom, id: RawTerm) -> ChildSpec
Preferred typed-ID boundary. The caller resolves BeamEncode(id) and passes
the resulting opaque term here; macro expansion itself carries no hidden
dictionary argument. At runtime the term is the exact supervisor child ID.
fn more(n: Nat) -> Positive
Strictly positive period of n + 1 seconds.
fn one() -> Positive
Strictly positive period of 1 second.
fn one_for_all() -> Strategy
Supervision strategy: restart all children when any child terminates.
fn one_for_one() -> Strategy
Supervision strategy: restart only the terminated child.
fn option_syntax_or(value: Option(Syntax), fallback: Syntax) -> Syntax
Unwrap an optional syntax node, returning fallback when None.
fn permanent() -> Restart
Restart policy: always restart the child when it terminates.
fn positive_nat(period: Positive) -> Nat
Convert the closed strategy vocabulary to the ordinary supervisor tuple.
The strategy itself cannot be an arbitrary atom at a checked call site.
OTP permits zero restart intensity, but its restart period must be
strictly positive. Positive encodes that distinction without an
assertion or unchecked integer conversion.
fn raw_arg(a: Type, value: a) -> RawTerm
Explicit raw-term child arguments for a heterogeneous BEAM MFA list.
Every element must cross raw_arg/1 at the call site; no typed value is
silently widened by this constructor.
fn raw_args(a: Type, args: List(a)) -> List(RawTerm)
fn rest_for_one() -> Strategy
Supervision strategy: restart the terminated child and all children started after it.
fn restart_atom(restart: Restart) -> Atom
fn shutdown_after(timeout: Nat) -> Shutdown
Shutdown policy: wait up to timeout milliseconds for graceful shutdown.
fn shutdown_value(shutdown: Shutdown) -> Nat
fn supervision_strategy(strategy: Strategy, intensity: Nat, period: Positive) -> StrategySpec
Build an OTP supervision strategy tuple {strategy, intensity, period} from
the closed Strategy vocabulary, restart intensity, and strictly positive period.
fn supervisor() -> ChildType
Child type marking a nested supervisor process.
fn supervisor_child_ids(children: List(ChildDefinitionSyntax)) -> List(Syntax)
Collect enum variant syntax nodes for each child identity in a sup block.
fn supervisor_child_kind(kind: Syntax) -> Syntax
Translate a child kind keyword (supervisor, actor, or worker) into its
Std.Supervisor constructor call AST, failing on unknown kinds.
fn supervisor_child_specs(children: List(ChildDefinitionSyntax)) -> List(Syntax)
Lower each child definition in a sup block into a child_with_encoded call AST.
fn syntax_constructor(value: Syntax) -> Syntax
Convert an identifier syntax node into a nullary constructor call, leaving other syntax nodes unchanged.
fn syntax_key(value: Syntax) -> Option(Atom)
Extract the :constructor_key atom attribute from a syntax node, if present.
fn temporary() -> Restart
Restart policy: never restart the child when it terminates.
fn transient() -> Restart
Restart policy: restart the child only on abnormal termination.
fn worker() -> ChildType
Child type marking a supervised worker process.