- Use concurrency and recursion to manage state
- separate of client and server
- used diff abstractions for asynchronous and synchronous communication with server
- don't need to worry about ref
- GenServer in control of
receive
loop
- trust error reporting to log errors so we can fix what's broken
- automatically restart services in last good state
- self-healing software
- child_spec defines the children that an Elixir app will start
- server can crash and then restart w/ a supervisor
- :permanent, child is always restarted (default)
- :temporary, child is never restarted. Useful for when a restart is unlikely to resolve problem
- :transient, child is restarted only if it termiantes abnormally (with exit reason other than :normal, :shutdown, or {:shutdown, term}
More options
- max_restarts and max_seconds
- OTP only restart application max_restarts times in max_seconds before failing and reporting error up supervision tree
- one_for_one, if child terminates, supervisor restarts only that process
- one_for_all, if child termiantes, supervisor terminates all children and then restarts all children
- rest_for_one, if child terminates, supevisor terminates all child processes defined after the one that dies. Supervisor restarts all terminated processes
- simple_one_for_one, used when supervisor needs to dynamically supervise processes
Q: kill all children in that part of the tree?
- simpler abstraction of benefits of GenServer
- agent has five main functions: start_link, stop, update, get, get_and_update
- pass functions?
- What's the point?
- behind the scenes, agent is OTP genserver
- can give process a name by passing it into start_link and then send messages to the process by name
- Agents are constructs built on top of OTP
- build a tree of supervisors where each node knows how to restart any major service if it fails