3 ms·
Supervisors aren't just for restarting processes that crash, they're also responsible for cleaning up processes when the tree is being shutdown. If you're usin
by Ixiaus 10y ago
Supervisors aren't just for restarting processes that crash, they're also responsible for cleaning up processes when the tree is being shutdown.
If you're using spawn to fire off a long-ish running process that is too small in scope to justify making a gen_<something>, you might be doing it wrong. You can easily affix the logic you need as a process on a supervisor which will (very importantly) help clean up those processes for you.
A common pattern is to use a high-level supervisor for starting up the primary gen_<whatever>'s with sub-supervisors responsible for short-lived and long-lived "small logic" children - you can also ask a supervisor to add and start a new child and to remove one, let the supervisors do the bookkeeping!
Supervisors make your process trees declarative and help you avoid process soup, even when the processes aren't that important. I highly recommend harnessing that as much as possible when designing non-trivial Erlang programs.
- dvcrn 10y agoInteresting thoughts, thank you! I myself am guilty of spawning a few processes here and there that I consider not important enough to put into a supervisor.
- greenleafjacob 10y agoI think the fact that Erlang provides an incentive for declaring what processes are managed upfront is a great benefit. I find myself planning a bit the structure of the supervision tree whereas in Go there is no benefit so it's much more ad hoc and messy.
- jerf 10y agoI wrote suture for that: https://github.com/thejerf/suture https://github.com/thejerf/suture Do check out the "blog post describing the design decisions" I mention in the README.md; you don't need to tell me every precise way in which it differs from Erlang and why Go can't be exactly like Erlang, I've already done that for you. Like you, I have found it useful for structuring programs in many ways moreso than for reliability. That said, the reliability does sometimes end up being helpful.