Skip to content

Instantly share code, notes, and snippets.

@tastywheat
Last active July 16, 2016 14:57
Show Gist options
  • Save tastywheat/13bf62f69c077a138b2458df7b3cc330 to your computer and use it in GitHub Desktop.
Save tastywheat/13bf62f69c077a138b2458df7b3cc330 to your computer and use it in GitHub Desktop.
GenServer perpetual ticker
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