You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The error object returned in onFailedAttempt returns the wrong counts for the attempts.
constretry=require('p-retry');functiontest(times){letc=0;returnfunctionprom(){letp;if(times===c){p=Promise.resolve('true');}else{p=Promise.reject(newError('false'));}c+=1;returnp;};}constf=test(3);retry(f,{retries: 3,maxTimeout: 0,minTimeout: 0,onFailedAttempt(e){console.log(`Attempt ${e.attemptNumber} failed. There are ${e.attemptsLeft} attempts left.`);},}).then(v=>{console.log('success',v);}).catch(e=>{console.log('fail',e);});
The above prints out
$ node index.js
Attempt 1 failed. There are 2 attempts left.
Attempt 2 failed. There are 1 attempts left.
Attempt 3 failed. There are 0 attempts left.
success true
Maybe I'm using it wrong but if I have some type of logging in onFailedAttempt that checks to see if error.attemptsLeft === 0 and then logs that an operation failed. That may not be true. The very last attempt could still succeed.
The text was updated successfully, but these errors were encountered:
Yes, you are right. Thanks for raising the issue and sorry for the late reply.
I believe the issue was introduced as a result of an oversight when reading through retry's documentation which states "when retries is set to 1 it means do it once and retry once". On top of the changes you propose in #12, and for the sake of correctness, maybe we should rename attemptsLeft to retriesLeft because, apparently, the first attempt does not account for a retry. This change obviously introduces a breaking change, but I think it's worth it.
The error object returned in
onFailedAttempt
returns the wrong counts for the attempts.The above prints out
Maybe I'm using it wrong but if I have some type of logging in
onFailedAttempt
that checks to see iferror.attemptsLeft === 0
and then logs that an operation failed. That may not be true. The very last attempt could still succeed.The text was updated successfully, but these errors were encountered: