-
Notifications
You must be signed in to change notification settings - Fork 60
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 promise support for onRetryAttempt and shouldRetry #223
Conversation
I didn't see any harm in allowing promises in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable to me, but it would be good to also have @JustinBeckwith's thoughts.
Since retry is already async, I think you're right that this probably isn't a breaking change.
src/retry.ts
Outdated
@@ -55,7 +55,8 @@ export async function getRetryConfig(err: GaxiosError) { | |||
|
|||
// Determine if we should retry the request | |||
const shouldRetryFn = config.shouldRetry || shouldRetryRequest; | |||
if (!shouldRetryFn(err)) { | |||
const shouldRetryFnPromise = Promise.resolve(shouldRetryFn(err)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this Promise.resolve
necessary, await false
would just resolve false
right?
test/test.retry.ts
Outdated
@@ -219,6 +218,32 @@ describe('🛸 retry & exponential backoff', () => { | |||
scopes.forEach(s => s.done()); | |||
}); | |||
|
|||
it('should notify on retry attempts, including promises', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be tempted to make this assertion something like:
accepts async onRetryAttempt handler
Thanks for the review @bcoe! I was seeing a lot of tests failing without the resolve, I'll hopefully find some time to look into why tomorrow. I renamed the test |
Found any time @JustinBeckwith ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Want to make sure @bcoe is happy too :)
Codecov Report
@@ Coverage Diff @@
## master #223 +/- ##
=========================================
Coverage ? 95.84%
=========================================
Files ? 6
Lines ? 602
Branches ? 99
=========================================
Hits ? 577
Misses ? 24
Partials ? 1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @atjeff testing out your branch, this approach worked great for me:
// Determine if we should retry the request
const shouldRetryFn = config.shouldRetry || shouldRetryRequest;
- const shouldRetryFnPromise = Promise.resolve(shouldRetryFn(err));
- if (!(await shouldRetryFnPromise)) {
+ if (!(await await shouldRetryFn(err))) {
return {shouldRetry: false, config: err.config};
}
What tests were failing for you prior to the resolving step? I wonder if it might have been something else biting you. If we can do without the Promise.resolve
, I rather would 👌
Yep, it was me not thinking to await twice. Woops! Pushing that change now. |
I'm not sure how I had failing tests, sorry about that. Awaiting shouldRetryFn(err) works fine. Pushed @bcoe |
Thanks for taking the time guys! |
sorry I dig it back, but from the discussion I expected that retry will wait for both: Lines 75 to 77 in dd3eead
do I miss something? |
061afa3 commit 061afa3 Author: Jeff Hage <[email protected]> Date: Thu Jan 30 18:59:37 2020 -0500 feat: add promise support for onRetryAttempt and shouldRetry (#223)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #144 🦕