DynamicSupervisor
template, children, process, running, maxRestarts, maxSeconds, restartTimes
A dynamic supervisor that manages a pool of identical children started
from a single template spec. Unlike Supervisor, children are not
defined upfront — they are started on demand with startChild:.
All children share the same restart policy from the template spec.
When a child crashes, it is restarted individually (like #oneForOne).
This is equivalent to Erlang's simple_one_for_one / DynamicSupervisor.
ds := DynamicSupervisor new: (ChildSpec id: 'worker' start: [nil] restart: #temporary).
ds template id >>> 'worker'
"Create a pool of workers"
| template <ChildSpec> ds <DynamicSupervisor> |
template := ChildSpec id: 'worker' start: [:id | Worker new: id run] restart: #permanent.
ds := DynamicSupervisor new: template.
ds start.
"Start workers on demand"
ds startChild: 'worker-1'.
ds startChild: 'worker-2'.
ds startChild: 'worker-3'.
"Query"
ds countChildren. "=> 3"
ds runningChildren. "=> #('worker-1' 'worker-2' 'worker-3')"
"Remove a specific child"
ds terminateChild: 'worker-2'.
ds stop
Class Methods
uncategorized
Create a DynamicSupervisor with a template ChildSpec.
Instance Methods
uncategorized
Return the count of running children.
Return the supervisor process.
Return the IDs of currently running children.
Start the dynamic supervisor process.
Start a new child with the given ID. The template's start block is evaluated with the ID as argument.
Stop the dynamic supervisor and all children.
Return the template spec.
Terminate a child by ID.