"sample" an agent every second?

Hey all and future search engine visitors (like me). I wanted to mention something I feel was missed here. In case it matters to your program, you can ensure that your initial :tick message is sent after GenServer’s event loop is started by using the handle_continue/2 callback.

@impl true
def init(state) do
  {:ok, state, {:continue, :init}}
end

@impl true
def handle_continue(:init, state) do
  send(self(), :tick)
  {:noreply, state}
end