Skip to content

Commit b70aa23

Browse files
committed
Small fix for ticker start_tick logic so that it doesn't receive an extra tick call from event_consumer on every update
1 parent 58bbd59 commit b70aa23

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

lib/ecstatic/ticker.ex

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ defmodule Ecstatic.Ticker do
4646
end
4747

4848
def handle_info({:start_tick, c_id, system, entity_id, [every: interval, for: ticks]}, state) do
49-
send(self(), {:tick, c_id, system, interval})
50-
new_state = state |>
51-
update_ticks(c_id, ticks) |>
52-
Map.put(:entity_id, entity_id)
53-
{:noreply, new_state}
49+
case Map.get(state.ticks, c_id) do
50+
^ticks -> {:noreply, state}
51+
t when t < ticks -> {:noreply, state}
52+
_ ->
53+
send(self(), {:tick, c_id, system, interval})
54+
new_state = state |>
55+
update_ticks(c_id, ticks) |>
56+
Map.put(:entity_id, entity_id)
57+
{:noreply, new_state}
58+
end
5459
end
5560

5661
def handle_info({:stop_tick, c_id}, state) do

0 commit comments

Comments
 (0)