Retry Loop Retry
18 days ago
- #programming
- #error-handling
- #retry-loop
- The author discusses the challenges of writing a retry loop that meets specific requirements: bounded retries, no extra sleep after the last attempt, original error reporting, and no code duplication.
- Initial attempts focused on ensuring the number of retries is syntactically bounded, leading to complex code shapes.
- A better approach is to loop while the action returns an error, with retries as an early exit condition, making the loop more flexible for different retry conditions (e.g., time-based).
- The 'obviously bounded' requirement can be restored by adding an upper bound to the loop, though this introduces potential pitfalls like off-by-one errors.