Skip to main content

Practice ยท 2 of 2

Retry with exponential backoff

CHALLENGE
Difficulty: advanced+25 XP

Implement static async Task<int> RetryAsync(Func<int> attempt, int maxAttempts, int baseDelayMs) calling attempt() up to maxAttempts times: on success return the value; on failure await Task.Delay(baseDelayMs * 2^attemptIndex) before the next try (attemptIndex starting at 0). After exhausting attempts throw InvalidOperationException. The test verifies backoff timing directly: with 3 attempts and baseDelayMs=50 the total must reach at least 50 + 100 = 150ms (the exception must propagate too โ€” no sentinel returns).

Back to lesson: Practice: Diagnostics drills