Skip to content

Commit

Permalink
logic fix in debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
whossname committed Feb 3, 2022
1 parent 3866399 commit 2269b2e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/slack_logger_backend/producer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ defmodule SlackLoggerBackend.Producer do
%{state | event_map: event_map}
else
# handle new event
unless is_nil(state.debounce) do
Process.send_after(self(), :process_demand, state.debounce * 1000 + 1)
end

queue = :queue.in({time, event}, state.queue)
event_map = Map.put(state.event_map, event, 1)
%{state | event_map: event_map, queue: queue}
Expand Down Expand Up @@ -62,7 +66,7 @@ defmodule SlackLoggerBackend.Producer do
{:noreply, events, state}

{{:value, {time, event}}, queue} ->
if is_nil(state.debounce) or state.debounce > System.monotonic_time(:second) - time do
if is_nil(state.debounce) or state.debounce <= System.monotonic_time(:second) - time do
count = Map.get(state.event_map, event)
event_map = Map.delete(state.event_map, event)
state = %{state | demand: demand - 1, queue: queue, event_map: event_map}
Expand Down

0 comments on commit 2269b2e

Please sign in to comment.