A surface's derived sources run once per host (spec/03 §3.1, dco-tek/macaw/macaw#108 "A
derived source is a managed source"): a process holding one Macaw.Data.Derived.Engine
for every page that mounts a surface with the same derived sources over the same inputs.
- Keyed (
key/4) by the digest of the engine's definitions (its derived sources, the sources they may read, its functions, debounce and bounds) and the key of each input's source manager (Macaw.Data.Manager.key/4), so a viewer-dependent input makes the engine its viewer's. Started under<live>.Ownersby the first page that finds none (ensure/3), registered in the supervisor'sRegistrywith its table, and lingeringlinger:(5,000 ms) after the last page leaves, as a manager does. - Its inputs are managed: it subscribes each source its engine reads, whole, to that
source's manager as a reader of its own, and reads each from the manager's table
(
Macaw.Data.Manager.Reader.read/3), so an input read by pages and by the engine is one holding and one finish. - A writer only, its work in turns. A manager's message that an input changed arms
a read
debounce:later, so changes within it are one pulse; the read, the engine'spush/4and its due pulse (run/2) are one turn of its own under<live>.Tasks, given a copy of the engine and answering the engine, bounded bytimeout:, a turn asked meanwhile run once after. A pulse due later is armed for when it is due. - Its outputs are sources: each output's last good delivery and status is
published in its table, and read by its output's manager through
Macaw.Live.Derived.Source, an entry that names this process's key and the output's path, so its digest never moves. An output whose delivery or status moved is announced on its name's topic (spec/03 §7), once; an unchanged answer announces nothing, so it marks no reader.
A page holding a surface with derived sources joins it at mount (join/2) and leaves at
unmount, and is watched while it holds it.
Summary
Types
A derived process's key: {:derived, digest, inputs}, the digest of its engine's
definitions and each input's manager key by source name.
Functions
Returns a specification to start this module under a supervisor.
The process of key under live, started when none runs: {:ok, pid}, the one started
first when two race, or {:error, reason}. opts: engine:, inputs: (by source
name, {manager key, the manager's ensure options}), viewer:, the first page's
clock:, timeout: and debounce:, and linger:.
The process's present state: its key, engine (Engine.runs/1, Engine.status/1 and
Engine.faults/1 read it), inputs' managers, pages, turn running and whether a read or
a pulse is armed. {:ok, info}, or {:error, reason}.
page joined: watched while it holds the surface. :ok, never waiting.
The key of the process running engine over inputs, each source name it reads with
its manager's key.
page left. :ok, never waiting.
The process of key and its table: {:ok, pid, table}, or :error.
The output at path as the process of key last published it: {:ok, delivery, status}, its last good delivery (nil for none) and the derived source's status, or
:loading before it published one or with none running. Never calls the process.
Types
@type key() :: {:derived, String.t(), [{String.t(), Macaw.Data.Manager.key()}]}
A derived process's key: {:derived, digest, inputs}, the digest of its engine's
definitions and each input's manager key by source name.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
The process of key under live, started when none runs: {:ok, pid}, the one started
first when two race, or {:error, reason}. opts: engine:, inputs: (by source
name, {manager key, the manager's ensure options}), viewer:, the first page's
clock:, timeout: and debounce:, and linger:.
The process's present state: its key, engine (Engine.runs/1, Engine.status/1 and
Engine.faults/1 read it), inputs' managers, pages, turn running and whether a read or
a pulse is armed. {:ok, info}, or {:error, reason}.
page joined: watched while it holds the surface. :ok, never waiting.
@spec key(Macaw.Data.Derived.Engine.t(), [{String.t(), Macaw.Data.Manager.key()}]) :: key()
The key of the process running engine over inputs, each source name it reads with
its manager's key.
page left. :ok, never waiting.
The process of key and its table: {:ok, pid, table}, or :error.
@spec output(atom(), key(), [String.t()]) :: {:ok, Macaw.Data.Delivery.t() | nil, term()} | :loading
The output at path as the process of key last published it: {:ok, delivery, status}, its last good delivery (nil for none) and the derived source's status, or
:loading before it published one or with none running. Never calls the process.