Side-effect descriptors returned from init/1 and update/2.
An app's update/2 can return {new_model, cmd} to request side-effects.
The runtime dispatches the cmd to a Task.Supervisor and re-enters the
TEA loop; results arrive later as ordinary {:harlock_event, result}
messages that update/2 handles like any other event.
def update(:fetch, model) do
cmd = Cmd.from(fn -> HTTPoison.get!("https://example.com") end)
{model, cmd}
end
def update({:ok, %{body: body}}, model), do: {%{model | body: body}, Cmd.none()}Constructors:
none/0— no side-effect. Equivalent to returning just the model.from/1— run a 0-arity function in a task; deliver its return value.batch/1— dispatch a list of cmds concurrently; no ordering guarantee.map/2— tag/transform the result of an inner cmd before delivery.
Task lifecycle: cmd tasks are supervised by Harlock.App.TaskSupervisor,
itself a child of the app's supervisor positioned after Runtime. A
Runtime exit terminates the task supervisor and all in-flight tasks
(rest_for_one). A task crash is caught at the task body and delivered
as {:cmd_error, reason}; it never propagates to the runtime.