Macaw.Live.Supervisor (macaw_live v0.1.0)

Copy Markdown View Source

The supervisor a host adds to its tree; everything the runtime starts lives under it (spec/01 §1). Copied from visualize's Visualize.Board.Supervisor and adapted: host-named, its children fixed, and no application process.

The library starts no process of its own (visualize spec/15 §8.1, D-146). It has no application callback that starts anything; a host adds one supervisor, names it, and passes the name wherever the runtime is used:

children = [
  {Macaw.Live.Supervisor, name: MyApp.Macaw},
  MyAppWeb.Endpoint
]

Its children, :one_for_one, each named from the host's name:

  • <name>.Registry, a Registry of unique keys: pages and regions by transport, and the default owners (spec/04);
  • <name>.Topics, a Registry of duplicate keys: the default notification behavior's subscribers (spec/03 §7);
  • <name>.Cells, a DynamicSupervisor of every contained cell, :temporary (spec/02);
  • <name>.Owners, a DynamicSupervisor of every :shared owner and source manager, :transient (spec/04, spec/03 §2);
  • <name>.Tasks, a Task.Supervisor of turns and proofs (spec/03 §2.1, spec/01 §3.3);
  • <name>.Tables, the heir of every source manager's table, which keeps it a grace past the manager's end (spec/03 §2);
  • the asset store's process, when the store needs one: a store module exporting child_spec/1 is started with its argument and name: <name>.Assets (spec/06 §2);
  • the proxy cache's process, when the cache needs one, the same way, as <name>.ProxyCache (spec/06 §1.5);
  • the render memo's process, when the memo needs one, the same way, as <name>.Renders (spec/01 §3.4).

It loads the node's application code before it starts them (spec/01 §3.3), as a release in embedded mode has it loaded: a proof's liveness bound times a render blocked, and a render's first call of a module not yet loaded waits on the node's one code server, which a loaded host can keep past render_timeout:, the cell then drawn crashed :hung (macaw_live#116). For a release this checks each module and loads none.

Summary

Functions

The name of one of the supervisor's children, derived from the host's name: :registry, :topics, :cells, :owners, :tasks, :managers (macaw_data's Macaw.Data.Manager.Supervisor), :tables (its tables' heir, which a derived output's table is handed to as well), :assets, :proxy_cache or :renders.

Its child spec, for a host's tree: a supervisor, its id the name given.

Whether a supervisor of this name is running: a host passes the name as live:, and a name not started is {:not_running, name} there (spec/01 §2).

Starts the supervisor (spec/01 §1): {:ok, pid}, or {:error, faults} with every fault of its options at once, by key. name: is required, an atom: the supervisor's registered name, every child's derived from it. notify:, owners:, assets:, proxy_cache: and renders: are each {module, arg} of a loaded module implementing its behavior (owners: the :via protocol's four functions, its default the supervisor's own Registry). detectors: maps a source's name to its change detector (spec/03 §7.1): {module, opts} or {module, opts, every: ms} of a module implementing macaw_data's Macaw.Data.Source.Detector, %{} by default. memory: is the bytes the host's source managers may hold together (spec/03 §2.4), a positive integer, nil (no budget) by default.

start_link/1, raising its faults as an ArgumentError for a host at boot: the pid, or the raise.

Functions

child(name, atom)

@spec child(
  atom(),
  :registry
  | :topics
  | :cells
  | :owners
  | :tasks
  | :managers
  | :tables
  | :assets
  | :proxy_cache
  | :renders
) :: atom()

The name of one of the supervisor's children, derived from the host's name: :registry, :topics, :cells, :owners, :tasks, :managers (macaw_data's Macaw.Data.Manager.Supervisor), :tables (its tables' heir, which a derived output's table is handed to as well), :assets, :proxy_cache or :renders.

iex> Macaw.Live.Supervisor.child(MyApp.Macaw, :tasks)
MyApp.Macaw.Tasks
iex> Macaw.Live.Supervisor.child(MyApp.Macaw, :managers)
MyApp.Macaw.Managers

child_spec(init_arg)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Its child spec, for a host's tree: a supervisor, its id the name given.

running?(name)

@spec running?(term()) :: boolean()

Whether a supervisor of this name is running: a host passes the name as live:, and a name not started is {:not_running, name} there (spec/01 §2).

start_link(opts)

@spec start_link(term()) ::
  {:ok, pid()} | {:error, [Macaw.Base.Fault.t(), ...] | term()}

Starts the supervisor (spec/01 §1): {:ok, pid}, or {:error, faults} with every fault of its options at once, by key. name: is required, an atom: the supervisor's registered name, every child's derived from it. notify:, owners:, assets:, proxy_cache: and renders: are each {module, arg} of a loaded module implementing its behavior (owners: the :via protocol's four functions, its default the supervisor's own Registry). detectors: maps a source's name to its change detector (spec/03 §7.1): {module, opts} or {module, opts, every: ms} of a module implementing macaw_data's Macaw.Data.Source.Detector, %{} by default. memory: is the bytes the host's source managers may hold together (spec/03 §2.4), a positive integer, nil (no budget) by default.

Faults: {[:name], :required}, {[:name], {:type, :atom}}, {[key], :unknown_key}, and {[key], {:type, behavior}} for a notify:, owners:, assets:, proxy_cache: or renders: it can't use, {[:detectors], {:type, :map}}, and {[:detectors, name], {:type, Macaw.Data.Source.Detector}} for a detector it can't use, and {[:memory], {:type, :pos_integer}}. Options that aren't a keyword list are {[], {:type, :keyword}}.

start_link!(opts)

@spec start_link!(keyword()) :: pid()

start_link/1, raising its faults as an ArgumentError for a host at boot: the pid, or the raise.