safwank / ElixirRetry

Simple Elixir macros for linear retry, exponential backoff and wait with composable delays
Other
441 stars 32 forks source link

Fix dialyzer issue in wait macro #34

Closed jdenen closed 5 years ago

jdenen commented 5 years ago

Using wait like this:

@spec something() :: :foo | :bar
def something() do
  wait [10] |> Stream.cycle() |> Stream.take(10) do
    true_or_false?(true)
  after
    _ -> :foo
  else
    _ -> :bar
  end
end

@spec true_or_false?(boolean()) :: boolean()
defp true_or_false?(true), do: true
defp true_or_false?(false), do: false

I would receive this dialyzer issue:

lib/something.ex:15:pattern_match
The pattern can never match the type.

Pattern:
_ = nil

Type:
true
________________________________________________________________________________

I tracked it down to the pattern match against false/nil being separate lines. If you have a function returning true or false, you'll never match against nil. Dialyzer doesn't like that.

This PR fixes it, from what I can tell.

safwank commented 5 years ago

Thanks heaps for the PR @jdenen!