DynamicSupervisor

Inherits from: Object
Instance variables: 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.

Test
ds := DynamicSupervisor new: (ChildSpec id: 'worker' start: [nil] restart: #temporary).
ds template id >>> 'worker'
Example
"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

class new:

Create a DynamicSupervisor with a template ChildSpec.

class new:maxRestarts:maxSeconds:

Instance Methods

uncategorized

countChildren

Return the count of running children.

findChildId:
handleChildDown:
primInit:maxR:maxS:
printString
process

Return the supervisor process.

recordRestart
restartIntensityExceeded
runLoop
runningChildren

Return the IDs of currently running children.

shouldRestart:
start

Start the dynamic supervisor process.

startChild:

Start a new child with the given ID. The template's start block is evaluated with the ID as argument.

stop

Stop the dynamic supervisor and all children.

template

Return the template spec.

terminateAllChildren
terminateChild:

Terminate a child by ID.