Skip to content

Instantly share code, notes, and snippets.

@TylerPachal
Created November 9, 2017 18:47
Show Gist options
  • Save TylerPachal/8aab808ab79f6aa619294ef845d1d042 to your computer and use it in GitHub Desktop.
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
## 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