I have a simple GenServer
within which I wish to create a loop that calls a function every two seconds:
defmodule MyModule do
use GenServer
def start_link(time) do
GenServer.start_link(__MODULE__,time)
end
#Start loop
def init(time) do
{:ok, myLoop(time)}
end
#Loop every two seconds
def myLoop(time) do
foo = bah(:someOtherProcess, {time})
IO.puts("The function value was: #{foo}")
:timer.sleep(2000)
myLoop(time + 2)
end
end
But when I call with:
{:ok, myServer} =MyModule.start_link(time)
IO.puts("Now I can carry on...")
I never see a return from the above call. This is kind of obvious I guess. So my question is, how can I create the loop I'd like without blocking the process from downstream execution tasks?
Thanks.