Skip to content

Instantly share code, notes, and snippets.

@minhajuddin
Created July 18, 2018 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minhajuddin/db348c68b5afc21c4820bb8907031d06 to your computer and use it in GitHub Desktop.
Save minhajuddin/db348c68b5afc21c4820bb8907031d06 to your computer and use it in GitHub Desktop.
defmodule SearchWorker do
use GenServer
@idle_timeout_ms 10 * 60 * 1000
@impl GenServer
def init(state) do
# send ourselves a message after 10 seconds and cleanup the proc tree when we get this
Process.send_after(self(), :idle_timeout, @idle_timeout_ms)
{:ok, state}
end
@impl GenServer
def handle_info(:idle_timeout, state) do
# do whatever you want to do to cleanup your process tree
shutdown_proc_tree(state)
{:noreply, state}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment