gcanti/retry-ts

Is it possible to get the attempt number?

amaury1093 opened this issue · 3 comments

In the example in the README, I would like to also log the attempt number, something like:

const logDelay = (delay: number, attempt: number) => TE.rightIO(log(`Attempt #${attempt} failed, retrying in ${delay} milliseconds`))

Right now, I'm setting a let attempt = 0; outside of the retrying() function, and doing a side effect to increment it on every retry. But maybe there's a cleaner way?

Thanks, that works.

Follow-up question: how about if I want to show, on each retry, the error message returned by the previous (failed) attempt?

+1 for the follow-up question:

how about if I want to show, on each retry, the error message returned by the previous (failed) attempt?