Retry requests with exponential backoff
Retry an asynchronous operation with bounded exponential delays, cancellation, and injectable scheduling.Description
Requirements
The solution exports the required retryWithBackoff API from the editable module.
Exponential delays works deterministically for the documented normal, boundary, and repeated-use scenarios.
Success stops works deterministically for the documented normal, boundary, and repeated-use scenarios.
Max attempts works deterministically for the documented normal, boundary, and repeated-use scenarios.
Final error works deterministically for the documented normal, boundary, and repeated-use scenarios.
Abort works deterministically for the documented normal, boundary, and repeated-use scenarios.
Scheduler injection works deterministically for the documented normal, boundary, and repeated-use scenarios.
Success on the third attempt
maxAttempts 4, baseDelayMs 100; first two attempts reject
Delays are 100 and 200, then the third value resolves
No delay occurs before the first attempt or after a successful attempt.
Constraints
maxAttempts is a positive integerNever retry after an AbortSignal is abortedRethrow the final operation error unchanged
Hints
Hint 1
Count attempts from one and delays from zero so the first retry uses the base delay.
Hint 2
Check cancellation before the operation and before and after sleeping.
Hint 3
Inject sleep instead of hard-coding timers into the retry loop.