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 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

 type ChildSpec

enum ChildType

 enum ChildType
   Worker
   Supervisor

enum Positive

 enum Positive
   One
   More

enum Restart

 enum Restart
   Permanent
   Temporary
   Transient

enum Shutdown

 enum Shutdown
   Brutal
   Timeout

enum Strategy

 enum Strategy
   OneForOne
   OneForAll
   RestForOne

type StrategySpec

 type StrategySpec

Functions

brutal_shutdown() -> Shutdown

 fn brutal_shutdown() -> Shutdown

Shutdown policy: immediately terminate the child with :kill.

child(module: Atom, id: Atom) -> ChildSpec

 fn child(module: Atom, id: Atom) -> ChildSpec

Build a default permanent worker ChildSpec with a 5000 ms shutdown timeout.

child_type_atom(child_type: ChildType) -> Atom

 fn child_type_atom(child_type: ChildType) -> Atom

child_with(module: Atom, id: Atom, restart: Restart, shutdown: Shutdown, child_type: ChildType) -> ChildSpec

 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.

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))

 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.

child_with_encoded(module: Atom, id: RawTerm, restart: Restart, shutdown: Shutdown, child_type: ChildType) -> ChildSpec

 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.

child_with_raw_args(module: Atom, id: Atom, args: List(RawTerm), restart: Restart, shutdown: Shutdown, child_type: ChildType) -> ChildSpec

 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.

child_with_typed_args(a: Type, module: Atom, id: Atom, args: List(a), restart: Restart, shutdown: Shutdown, child_type: ChildType) -> ChildSpec

 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.

contains_identity(values: List(Syntax), expected: Atom) -> Bool

 fn contains_identity(values: List(Syntax), expected: Atom) -> Bool

Return true if expected matches the constructor key of any syntax node in values.

derive_supervisor_family(name: ModuleNameSyntax, definition: SupervisorDefinitionSyntax) -> Syntax

 fn derive_supervisor_family(name: ModuleNameSyntax, definition: SupervisorDefinitionSyntax) -> Syntax

Macro expander for sup: rejects duplicate child identities and otherwise delegates to derive_verified_supervisor.

derive_typed_child(module: ModuleNameSyntax, identity: Syntax) -> Syntax

 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.

derive_verified_supervisor(name: ModuleNameSyntax, definition: SupervisorDefinitionSyntax) -> Syntax

 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.

duplicate_child_identity(children: List(ChildDefinitionSyntax), found: List(Syntax)) -> Bool

 fn duplicate_child_identity(children: List(ChildDefinitionSyntax), found: List(Syntax)) -> Bool

Return true if any two child definitions share the same constructor key.

empty_raw_args() -> List(RawTerm)

 fn empty_raw_args() -> List(RawTerm)

Return an empty List(RawTerm) for child specs that take no start arguments.

encoded_child(module: Atom, id: RawTerm) -> ChildSpec

 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.

more(n: Nat) -> Positive

 fn more(n: Nat) -> Positive

Strictly positive period of n + 1 seconds.

one() -> Positive

 fn one() -> Positive

Strictly positive period of 1 second.

one_for_all() -> Strategy

 fn one_for_all() -> Strategy

Supervision strategy: restart all children when any child terminates.

one_for_one() -> Strategy

 fn one_for_one() -> Strategy

Supervision strategy: restart only the terminated child.

option_syntax_or(value: Option(Syntax), fallback: Syntax) -> Syntax

 fn option_syntax_or(value: Option(Syntax), fallback: Syntax) -> Syntax

Unwrap an optional syntax node, returning fallback when None.

permanent() -> Restart

 fn permanent() -> Restart

Restart policy: always restart the child when it terminates.

positive_nat(period: Positive) -> Nat

 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.

raw_arg(a: Type, value: a) -> RawTerm

 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.

raw_args(a: Type, args: List(a)) -> List(RawTerm)

 fn raw_args(a: Type, args: List(a)) -> List(RawTerm)

rest_for_one() -> Strategy

 fn rest_for_one() -> Strategy

Supervision strategy: restart the terminated child and all children started after it.

restart_atom(restart: Restart) -> Atom

 fn restart_atom(restart: Restart) -> Atom

shutdown_after(timeout: Nat) -> Shutdown

 fn shutdown_after(timeout: Nat) -> Shutdown

Shutdown policy: wait up to timeout milliseconds for graceful shutdown.

shutdown_value(shutdown: Shutdown) -> Nat

 fn shutdown_value(shutdown: Shutdown) -> Nat

supervision_strategy(strategy: Strategy, intensity: Nat, period: Positive) -> StrategySpec

 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.

supervisor() -> ChildType

 fn supervisor() -> ChildType

Child type marking a nested supervisor process.

supervisor_child_ids(children: List(ChildDefinitionSyntax)) -> List(Syntax)

 fn supervisor_child_ids(children: List(ChildDefinitionSyntax)) -> List(Syntax)

Collect enum variant syntax nodes for each child identity in a sup block.

supervisor_child_kind(kind: Syntax) -> Syntax

 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.

supervisor_child_specs(children: List(ChildDefinitionSyntax)) -> List(Syntax)

 fn supervisor_child_specs(children: List(ChildDefinitionSyntax)) -> List(Syntax)

Lower each child definition in a sup block into a child_with_encoded call AST.

syntax_constructor(value: Syntax) -> Syntax

 fn syntax_constructor(value: Syntax) -> Syntax

Convert an identifier syntax node into a nullary constructor call, leaving other syntax nodes unchanged.

syntax_key(value: Syntax) -> Option(Atom)

 fn syntax_key(value: Syntax) -> Option(Atom)

Extract the :constructor_key atom attribute from a syntax node, if present.

temporary() -> Restart

 fn temporary() -> Restart

Restart policy: never restart the child when it terminates.

transient() -> Restart

 fn transient() -> Restart

Restart policy: restart the child only on abnormal termination.

worker() -> ChildType

 fn worker() -> ChildType

Child type marking a supervised worker process.