Retry an Async Call, Keeping Its Result Type
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write retry(fn, attempts): call the async function fn, passing the attempt number (starting at 1), and if its promise rejects, call it again, up to attempts calls in all. Resolve with the first value it gives; if every attempt fails, reject with the last error. Type it so the result has fn's resolved type, the attempt number is a number, and a function that doesn't return a promise is rejected.
Your code must pass
- Resolves with the first success
- Passes the attempt number
- Rejects with the last error after the last attempt
- Has no type errors
- Resolves with fn's result type
- attempt is a number
- Rejects a function that doesn't return a promise