Closed nathanalderson closed 1 year ago
Thanks for the PR @nathanalderson! I've been wanting to do this for a while. I'll take a look at the PR this weekend and get back to you.
Went ahead and did wait
. This:
wait ... do
...
end
Is now equivalent to this:
wait ... do
...
after
result -> {:ok, result}
else
error -> {:error, error}
end
A few other notes:
After some thought, I realized that the appropriate thing to do in the default retry ... else
clause is to reraise if the last failure was an exception and return the failed value otherwise. That's now the behavior. In other words:
retry with: ... do
...
end
Is now equivalent to:
retry with: ... do
...
after
result -> result
else
e when is_exception(e) -> raise e
e -> e
end
Sorry, meant to mark this as ready. Let me know if you have feedback.
I have a follow-up PR that addresses some more needs I have including some discussed in #54.
Just bumping this a bit. Not super urgent but didn't want it to fall off your radar or something. Let me know if there's anything I can do to assist.
@nathanalderson Rest assured I haven't forgotten about this. I'm currently busy with life, so please bear with me.
Periodic bump. Would love to get this in and introduce a follow-up. 🙂
@nathanalderson Thanks for the fixes. A couple of comments
Sorry, the merge commit was accidental. That's the follow-up PR I've mentioned. Meant to merge upstream/master
instead of origin/master
. I've reverted. I also covered the two missed syntax errors in unit test.
I also added a comment to disable the complexity warning from credo on the main retry
macro. I tried moving the else/after logic into a function and that did fix the warning, but in my opinion it made things less readable. I'm open to doing that if you prefer.
This PR makes the
after
andelse
clauses optional. Essentially, this:Is now equivalent to:
I could be convinced to change the default
else
behavior to simply returning the exception, but re-raising it seems more natural to me.I also improved the error messaging slightly by calling out the specific option or clause the user messed up when possible. So you'll get a message like
you must provide a "do" clause
oroption "foo" is unsupported
instead of a more generic message.So far I have only done the implementation for the
retry
macro, but if you like the concept, I will updatewait
similarly. I thinkretry_while
is already fine in this respect since it only has ado
block.