Created
October 18, 2017 00:39
-
-
Save danj3/51a30984c378f00bb5c7b7294ac7d135 to your computer and use it in GitHub Desktop.
Elixir GenServer use of timeout as 3rd element return from init()
This file contains 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 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