hard+350 XPEnded 27 Jul
Retry a request with backoff
A request that fails once will often succeed on the next try. Retrying immediately just hammers a struggling server, so each wait should be longer than the last.
Implement retry(task, { attempts, baseDelay }) where task returns a promise. Retry on rejection until attempts run out, doubling the delay each time.
What it has to do
- Resolve as soon as any attempt succeeds.
- Reject with the last error once attempts are exhausted.
- Double the delay after each failure, starting at
baseDelay. - Make no extra call after the final attempt.
Your workspace
Try it yourself· Edit the code, then press Run
Loading playground...
Ready to check it?
4 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.
Stuck? The javascript course covers everything this challenge needs.