Guest User

Untitled

a guest
Jun 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. defmodule MyApplication.Recurring do
  2. use GenServer
  3.  
  4. def start_link() do
  5. GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
  6. end
  7.  
  8. def init(:ok) do
  9. schedule()
  10. {:ok, %{}}
  11. end
  12.  
  13. defp schedule do
  14. Process.send_after(self(), :do_work, 15 * 1000)
  15. end
  16.  
  17. def handle_info(:do_work, state) do
  18. IO.puts "My recurring task!!"
  19.  
  20. schedule()
  21.  
  22. {:noreply, state}
  23. end
  24. end
Add Comment
Please, Sign In to add comment