Supervisor
Processes
Start a tree of supervised processes.
In Server.application, put children on the supervisor field: the repo pool, jobs runner, websocket socket, and any [Platform] `supervised` workers. `OneForOne` is the usual strategy (only the failed child restarts).
Supervisor.new OneForOne
|> Supervisor.add (Repo.supervised repo)
|> Supervisor.add (Jobs.supervised jobsConfig)
|> Supervisor.add (Socket.supervised [ mount ])Child specs come from helpers like Repo.supervised, or from [Supervision] `worker` when you wrap `Actor.start` / `Platform.supervised` yourself. See `examples/03_todo_app` and `examples/15_jobs`.
Types
Builder
type Builder = BuilderA supervision tree that is still being configured.
Examples
Supervisor.new OneForOne : BuilderStrategy
type Strategy
= OneForOne
| OneForAll
| RestForOneHow failures propagate among supervised children.
- OneForOne: restart only the child that failed (most common) - OneForAll: restart every child when one fails - RestForOne: restart the failed child and every child started after it
Examples
OneForOneValues
new
new : Strategy -> BuilderStart building a supervision tree with the given restart strategy.
Examples
Supervisor.new OneForOneadd
add : ChildSpecification a -> Builder -> BuilderAdd a child specification to the tree.
Examples
Supervisor.add (Repo.supervised repo) treestart
start : Builder -> Result StartError (Started Supervisor)Start the supervision tree (used by tests and tooling). Server apps usually pass the builder to Server.application instead of calling start yourself.
Examples
Supervisor.start tree