Skip to content

Commit 4df7664

Browse files
committed
chore: reduce function nesting depth to satisfy credo
Flatten nested `if`/`with`/`case` blocks in `StartChild.undo/4` and `ProcessExit.run/3` to stay within the max nesting depth of 2.
1 parent 9224cdb commit 4df7664

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

lib/reactor/process/step/process_exit.ex

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,19 @@ defmodule Reactor.Process.Step.ProcessExit do
5555
{:ok, options} <- Spark.Options.validate(options, @opt_schema),
5656
{:ok, process} <- Keyword.fetch(arguments, :process),
5757
{:ok, reason} <- Keyword.fetch(arguments, :reason) do
58-
if options[:wait_for_exit?] do
59-
case terminate(process, reason, arguments[:timeout], context.current_step) do
60-
:ok -> {:ok, reason}
61-
{:error, reason} -> {:error, reason}
62-
end
63-
else
64-
Process.exit(process, reason)
65-
{:ok, reason}
58+
send_exit(process, reason, arguments[:timeout], options, context)
59+
end
60+
end
61+
62+
defp send_exit(process, reason, timeout, options, context) do
63+
if options[:wait_for_exit?] do
64+
case terminate(process, reason, timeout, context.current_step) do
65+
:ok -> {:ok, reason}
66+
{:error, reason} -> {:error, reason}
6667
end
68+
else
69+
Process.exit(process, reason)
70+
{:ok, reason}
6771
end
6872
end
6973
end

lib/reactor/process/step/start_child.ex

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,15 @@ defmodule Reactor.Process.Step.StartChild do
101101
@impl true
102102
def undo(pid, arguments, context, options) do
103103
with {:ok, arguments} <- Spark.Options.validate(Enum.to_list(arguments), @arg_schema),
104-
{:ok, options} <- Spark.Options.validate(options, @opt_schema) do
105-
if Keyword.get(options, :terminate_on_undo?, true) do
106-
with {:ok, %{id: id}} <- child_spec(arguments[:child_spec]) do
107-
ref = Process.monitor(pid)
108-
options[:module].terminate_child(arguments[:supervisor], id)
109-
await_exit(pid, ref, options[:termination_timeout], context.current_step)
110-
end
111-
else
112-
:ok
113-
end
104+
{:ok, options} <- Spark.Options.validate(options, @opt_schema),
105+
true <- Keyword.get(options, :terminate_on_undo?, true),
106+
{:ok, %{id: id}} <- child_spec(arguments[:child_spec]) do
107+
ref = Process.monitor(pid)
108+
options[:module].terminate_child(arguments[:supervisor], id)
109+
await_exit(pid, ref, options[:termination_timeout], context.current_step)
110+
else
111+
false -> :ok
112+
error -> error
114113
end
115114
end
116115

0 commit comments

Comments
 (0)