Skip to content

Instantly share code, notes, and snippets.

@emilsoman
Created September 21, 2016 06:51
Show Gist options
  • Save emilsoman/93b98c7553bbce291d879e23989ac2fe to your computer and use it in GitHub Desktop.
Save emilsoman/93b98c7553bbce291d879e23989ac2fe to your computer and use it in GitHub Desktop.
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