Skip to content

Commit 76d0071

Browse files
committed
Use with/1 instead of nested case statements
1 parent b4f0aa0 commit 76d0071

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lib/ex_health.ex

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,14 @@ defmodule ExHealth do
110110

111111
quote do
112112
def unquote(function_name)() do
113-
case Process.whereis(unquote(module)) do
114-
nil ->
115-
{:error, "no proc"}
116-
117-
pid ->
118-
case Process.info(pid) do
119-
nil ->
120-
{:error, "no proc"}
121-
122-
info ->
123-
case Keyword.fetch(info, :status) do
124-
{:ok, :running} -> :ok
125-
{:ok, :waiting} -> :ok
126-
_ -> {:error, "process not running/waiting"}
127-
end
128-
end
113+
with pid <- Process.whereis(unquote(module)),
114+
info <- Process.info(pid),
115+
{:ok, status} <- Keyword.fetch(info, :status),
116+
status == :running || :waiting do
117+
:ok
118+
else
119+
nil -> {:error, "no proc"}
120+
_ -> {:error, "process not running/waiting"}
129121
end
130122
end
131123
end

0 commit comments

Comments
 (0)