Skip to content

Commit

Permalink
fix: buffer data via cast when not in idle or busy state (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
abc3 authored Jun 13, 2024
1 parent 3321c10 commit d5636cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.61
1.1.62
12 changes: 11 additions & 1 deletion lib/supavisor/db_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ defmodule Supavisor.DbHandler do
end

# emulate handle_cast
def handle_event(:cast, {:db_cast, caller, bin}, state, %{sock: sock}) do
def handle_event(:cast, {:db_cast, caller, bin}, state, %{sock: sock})
when state in [:idle, :busy] do
Logger.debug(
"DbHandler: state #{state} <-- <-- bin #{inspect(byte_size(bin))} bytes, cast caller: #{inspect(caller)}"
)
Expand All @@ -421,6 +422,15 @@ defmodule Supavisor.DbHandler do
:keep_state_and_data
end

def handle_event(:cast, {:db_cast, caller, bin}, state, %{buffer: buff} = data) do
Logger.debug(
"DbHandler: state #{state} <-- <-- bin #{inspect(byte_size(bin))} bytes, cast caller: #{inspect(caller)}"
)

new_buff = [bin | buff]
{:keep_state, %{data | caller: caller, buffer: new_buff}}
end

def handle_event(_, {closed, _}, :busy, data) when closed in @sock_closed do
{:stop, :db_termination, data}
end
Expand Down

0 comments on commit d5636cd

Please sign in to comment.