What is the best way in elixir to create a foreground process that tick on every given amount of time?
My main problem is that an approach like:
defmoulde Ticker do
def tick do
do_something()
:timer.sleep(1000)
tick
end
end
works, but is wrong by design. It's definitely not ticking every second, but every second PLUS the time for do_something() to complete. I could spawn a process to handle the "something" but still there is a small lag.
Also, I'm trying to build a mix app, there is some GenServers involved, and a main foreground process (the one I'm asking here) that should call the servers every x seconds. Is there an otp way of doing this?