Created
September 21, 2016 06:51
-
-
Save emilsoman/93b98c7553bbce291d879e23989ac2fe to your computer and use it in GitHub Desktop.
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
defmodule MyServer do | |
use GenServer | |
def start_link do | |
GenServer.start_link(__MODULE__, [], name: __MODULE__) | |
end | |
def kill do | |
GenServer.cast(__MODULE__, :stop) | |
end | |
def handle_cast(request, state) do | |
case request do | |
:stop -> {:stop, :normal, state} | |
_ -> {:noreply, state} | |
end | |
end | |
def terminate(_reason, _state) do | |
IO.puts "Terminate callback will sleep for 2 seconds" | |
Process.sleep 2000 | |
end | |
end | |
Process.flag(:trap_exit, true) | |
MyServer.start_link | |
MyServer.kill | |
receive do | |
{:EXIT, _pid, :normal} -> IO.puts "Exit signal received by parent" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment