Skip to content

Instantly share code, notes, and snippets.

@danj3
Created October 18, 2017 00:39
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 danj3/51a30984c378f00bb5c7b7294ac7d135 to your computer and use it in GitHub Desktop.
Save danj3/51a30984c378f00bb5c7b7294ac7d135 to your computer and use it in GitHub Desktop.
Elixir GenServer use of timeout as 3rd element return from init()
defmodule TimeoutExample do
use GenServer
def init(_args), do: {:ok, 0, 5_000}
def handle_info(:timeout, state) do
IO.inspect(state)
{:noreply, state+1, 5_000 + state*1000}
end
end
iex> {:ok, p} = GenServer.start(TimeoutExample, [])
1
2
3
4
5
6
7
8
9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment