Std.App (Cure Standard Library v0.37.2)

View Source

OTP application declarations.

The app macro lifts an ApplicationDefinition into the generated application module: the supervision tree, start/stop callbacks, and the Cure.toml [application] / [release] wiring described in docs/APP.md.

Examples

use Std.App

app Demo
  root Root

Summary

Types

What happened when an application was asked to start.

Functions

ensure_all_started/1 answers {ok, Started} or {error, Reason}, where Started lists only the applications this call actually started. An empty list therefore means everything was already running.

get_env/2 answers {ok, Value} or the bare atom :undefined.

Start name together with every application it depends on.

Read one key of an application's environment.

Read key as an Atom, falling back when it is absent or is not one.

Read key as a Bool, falling back when it is absent or is not one.

Read key as an Int, falling back when it is absent or is not one.

Read key as a String, falling back when it is absent or is not one.

Whether a call that answers ok | {error, Reason} answered ok.

Length of a term the OTP contract already guarantees is a list. Guarded by its only caller, which reaches it after matching {ok, Started}.

Stop a running application. false means it was not running to begin with.

The payload of a two-element {tag, Payload} term, when the tag matches.

Types

enum AppStart

 enum AppStart
   AppStarted
   AlreadyStarted
   AppStartFailed

What happened when an application was asked to start.

AlreadyStarted is not a failure — OTP reports it as success with an empty list of newly-started applications, and a caller that only needs "is it running" can treat it the same as AppStarted. AppStartFailed carries no reason: the reason OTP supplies is an arbitrary term, and pretending it is an atom would be a lie at the boundary. Use Std.Io on the raw call, or OTP's own logging, when the reason itself matters.

Functions

decode_ensure_all_started(outcome: BeamTerm) -> AppStart

 fn decode_ensure_all_started(outcome: BeamTerm) -> AppStart

ensure_all_started/1 answers {ok, Started} or {error, Reason}, where Started lists only the applications this call actually started. An empty list therefore means everything was already running.

decode_env(outcome: BeamTerm) -> Option(BeamTerm)

 fn decode_env(outcome: BeamTerm) -> Option(BeamTerm)

get_env/2 answers {ok, Value} or the bare atom :undefined.

derive_application_family(name: ModuleNameSyntax, definition: ApplicationDefinitionSyntax) -> Syntax

 fn derive_application_family(name: ModuleNameSyntax, definition: ApplicationDefinitionSyntax) -> Syntax

Expand an app declaration into its generated family.

The expands with target of the app macro: takes the declared module name and the ApplicationDefinition body, and produces the syntax for the application module -- defaulting to Cure.Generated.Application when the name is not a literal atom.

ensure_all_started(name: Atom) -> Effect(AppStart)

 fn ensure_all_started(name: Atom) -> Effect(AppStart)

Start name together with every application it depends on.

env(name: Atom, key: Atom) -> Effect(Option(BeamTerm))

 fn env(name: Atom, key: Atom) -> Effect(Option(BeamTerm))

Read one key of an application's environment.

The value is whatever the manifest's [application.env] put there, so it arrives as an undecoded BeamTerm. Narrow it with Std.Beam, or use one of the typed readers below when the expected shape is a primitive.

env_atom(name: Atom, key: Atom, fallback: Atom) -> Effect(Atom)

 fn env_atom(name: Atom, key: Atom, fallback: Atom) -> Effect(Atom)

Read key as an Atom, falling back when it is absent or is not one.

env_bool(name: Atom, key: Atom, fallback: Bool) -> Effect(Bool)

 fn env_bool(name: Atom, key: Atom, fallback: Bool) -> Effect(Bool)

Read key as a Bool, falling back when it is absent or is not one.

env_int(name: Atom, key: Atom, fallback: Int) -> Effect(Int)

 fn env_int(name: Atom, key: Atom, fallback: Int) -> Effect(Int)

Read key as an Int, falling back when it is absent or is not one.

env_string(name: Atom, key: Atom, fallback: String) -> Effect(String)

 fn env_string(name: Atom, key: Atom, fallback: String) -> Effect(String)

Read key as a String, falling back when it is absent or is not one.

is_ok_atom(outcome: BeamTerm) -> Bool

 fn is_ok_atom(outcome: BeamTerm) -> Bool

Whether a call that answers ok | {error, Reason} answered ok.

raw_ensure_all_started(name: Atom) -> Effect(BeamTerm)

 fn raw_ensure_all_started(name: Atom) -> Effect(BeamTerm)

raw_get_env(name: Atom, key: Atom) -> Effect(BeamTerm)

 fn raw_get_env(name: Atom, key: Atom) -> Effect(BeamTerm)

raw_length(term: BeamTerm) -> Int

 fn raw_length(term: BeamTerm) -> Int

Length of a term the OTP contract already guarantees is a list. Guarded by its only caller, which reaches it after matching {ok, Started}.

raw_stop(name: Atom) -> Effect(BeamTerm)

 fn raw_stop(name: Atom) -> Effect(BeamTerm)

stop(name: Atom) -> Effect(Bool)

 fn stop(name: Atom) -> Effect(Bool)

Stop a running application. false means it was not running to begin with.

tagged_payload(term: BeamTerm, expected: Atom) -> Option(BeamTerm)

 fn tagged_payload(term: BeamTerm, expected: Atom) -> Option(BeamTerm)

The payload of a two-element {tag, Payload} term, when the tag matches.