safwank / ElixirRetry

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

move `atom in unquote(atoms)` out of the guards #62

Open velimir opened 1 year ago

velimir commented 1 year ago

Problem

def call(service, atoms \\ [:retry_error], rescue_only \\ [], fun) do
  retry with: delay_stream(service),
              rescue_only: rescue_only,
              atoms: atoms do
    # ... fun.()
  after
    result ->
      result
  else
    error ->
      error
  end
end

This code does not comply as when Elixir tries to expand the macro the expanded code refers to "atoms" variable which can not be used in a "in" expression used in a guard.

** (ArgumentError) invalid right argument for operator "in", it expects a compile-time proper list or compile-time range on the right side when used in guard expressions, got: atoms

Solution

Remove "in" expression from the guards to allow the atoms to be a variable.

@safwank What do you think?