July 2021
Intermediate to advanced
176 pages
4h 14m
English
DynamicSupervisor is another ready-to-use supervisor available to you. It can start any GenServer process on demand. Let’s add it to the supervision tree:
| | def start(_type, _args) do |
| | children = [ |
| | {DynamicSupervisor, strategy: :one_for_one, name: Jobber.JobRunner}, |
| | ] |
| | |
| | opts = [strategy: :one_for_one, name: Jobber.Supervisor] |
| | Supervisor.start_link(children, opts) |
| | end |
The strategy setting is required, and the only strategy that is currently accepted is :one_for_one. We will talk about supervisor strategies later in this chapter, so don’t worry about this for now.
Module-Based DynamicSupervisor | |
|---|---|
|
You can also define a DynamicSupervisor module, like we do later ... | |
Read now
Unlock full access