Editing
Quixir/Supervisors
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
The Quixir/Supervisors page is currently empty. == Overview == In Elixir, supervisors are used to manage the lifecycle of child processes. They are responsible for starting, stopping, and restarting child processes when needed, ensuring fault tolerance and reliability in the system. == Purpose == Supervisors play a key role in building fault-tolerant systems. By organizing processes into a supervision tree, supervisors can detect when a process crashes and automatically restart it, allowing the system to recover from faults without manual intervention. == How Supervisors Work == Supervisors are defined using the `use` macro from the `Supervisor` module. They specify a set of child processes that they supervise, along with strategies for restarting those processes in case of failure. === Child Specification === Each child process is defined using a child specification, which includes the module and arguments needed to start the process. === Restart Strategies === Supervisors define restart strategies that determine how child processes should be restarted after a failure. Some common strategies include: * `:one_for_one`: Only restart the failed process itself. * `:one_for_all`: Restart all child processes. * `:rest_for_one`: Restart the failed process and all others that were started after it. == Supervisor Strategies == Supervisors also define their own restart strategy, which determines how the supervisor itself should be restarted. Common strategies include: * `:one_for_one`: Only restart the failed supervisor. * `:one_for_all`: Restart the failed supervisor and all other supervisors in the supervision tree. * `:rest_for_one`: Restart the failed supervisor and all supervisors that were started after it. == Handling Failures == When a supervised process terminates abnormally, the supervisor receives an exit signal and can take appropriate action. This could involve restarting the process, logging the error, or escalating the error to a higher-level supervisor. == Example Usage == ```elixir defmodule MyApp.Supervisor do use Supervisor def start_link do Supervisor.start_link(__MODULE__, []) end def init([]) do children = [ worker(MyApp.Worker, []) ] supervise(children, strategy: :one_for_one) end end ``` == Conclusion == Supervisors are a fundamental building block in creating reliable and fault-tolerant systems with Elixir. By organizing processes into a supervision tree and defining appropriate restart strategies, developers can ensure that their applications can recover from failures and provide a robust user experience. == See Also == * [[Quixir/Processes]] * [[Quixir/GenServer]] * [[Quixir/Application]] * [[Quixir/Distributed Systems]] * [[Quixir/OTP]] * [[Quixir/Concurrency]] [[Category:Quixir]] [[Category:Concurrency]] [[Category:Distributed Systems]]
Summary:
Please note that all contributions to Elixir Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Elixir Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information