Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add way to run code between each retry attempt #49

Open
peterflynn opened this issue Aug 29, 2019 · 0 comments
Open

Add way to run code between each retry attempt #49

peterflynn opened this issue Aug 29, 2019 · 0 comments

Comments

@peterflynn
Copy link

For various use cases, you may want to run code after a failed attempt and before the next try. For example:

  • Want to log errors/warnings whenever a retry is needed or keep a count of how many retries something took on average
  • Want to do some cleanup after a failed attempt, e.g. clearing caches or closing a socket

You could argue that it could be better to do cleanup in a catch+rethrow at the end of the function being retried, but that's a bit more verbose (compared to encapsulating that boilerplate in the retry API itself). And for the first use case, where you want to log a warning on the second attempt (first retry) but not the first attempt, you have to resort to hacks like keeping a counter value somewhere.

Suggestion: add an option for a callback like beforeRetry which is run immediately before every retry attempt (but not before the very first attempt).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant