Last active
July 16, 2016 14:57
-
-
Save tastywheat/13bf62f69c077a138b2458df7b3cc330 to your computer and use it in GitHub Desktop.
GenServer perpetual ticker
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 ArticleImporter.Server do | |
use GenServer | |
def start_link(_args \\ []) do | |
GenServer.start_link(__MODULE__, %{}, name: __MODULE__) | |
end | |
def init(state) do | |
:erlang.send_after(1000, __MODULE__, :tick) | |
{:ok, state} | |
end | |
def handle_info(:tick, state) do | |
# do some work | |
:erlang.send_after(1000, __MODULE__, :tick) | |
{:noreply, state} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment