Created
November 9, 2017 18:47
-
-
Save TylerPachal/8aab808ab79f6aa619294ef845d1d042 to your computer and use it in GitHub Desktop.
Adding a new callback to the MySupervisor so that it can handle exiting children process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## OTP Callbacks | |
def handle_info({:EXIT, dead_pid, _reason}, state) do | |
# Start new process based on dead_pid spec | |
{new_pid, child_spec} = state | |
|> Map.get(dead_pid) | |
|> start_child() | |
# Remove the dead_pid and insert the new_pid with its spec | |
new_state = state | |
|> Map.delete(dead_pid) | |
|> Map.put(new_pid, child_spec) | |
{:noreply, new_state} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment