Retries with exponential backoff

A code exercise of about 15 minutes: read the statement, solve «Retries with exponential backoff» in the browser and get a review like in a real interview.

Code · 15 min
Loading…

Statement

Write retry(fn, { retries, baseMs }, sleep). Call fn; if it fails, wait with await sleep(ms) and try again, up to retries retries. Waits are baseMs, baseMs*2, baseMs*4… Return the first successful result or, when retries run out, reject with the last error. sleep is a parameter so it can be tested without really waiting.