A small Elixir project that messes around with OTP supervisors and GenServers. Built while learning how to chain supervisors, run dynamic workers, and keep processes talking to each other.
-
Counter — a GenServer that goes up and down. You
inc, youdec, youget. That's it. Lives under a dynamic supervisor so you can spin one up whenever you feel like counting something. -
Worker — another GenServer, dumber but friendlier. It answers
pingandstatus. Also dynamically supervised. -
WorkerSupervisor — a
DynamicSupervisorthat launches counters and workers on the fly. No need to define them all upfront. -
Supervisor — the top-level boss. It starts the process registry and the dynamic supervisor, and if either goes down it brings them back. That's the "one for one" strategy.
-
Registry — a local process registry (
Registrymodule). Counters and workers register themselves here by name, so you can find them without keeping track of PIDs.
# Fire up the supervision tree
App.start()
# Run the demo — starts two counters, two workers,
# increments, decrements, and pings around
App.demo()You should get a tuple back like:
{8, 5, {:ok, :alive, :w1}, %{status: :ok, id: :w2}}Honestly? To get hands-on with OTP. Reading docs is one thing, wiring up supervisors and watching processes come and go on your own machine is another. If you're learning Elixir and want to see how the pieces fit together, this might help.
- Elixir 1.20+
- A terminal
MIT — do whatever you want with it.