Elegant Retry Loops: Avoiding Redundancy and Unexpected Sleeps
The author explores writing an elegant retry loop that clearly bounds the number of retries, avoids spurious sleep after the last attempt, reports the original error if retrying fails, and avoids code duplication. Several approaches are compared, ultimately settling on a `try while` loop with an upper bound to guarantee termination, addressing boundary issues and potential runaway loops in previous solutions. While the final solution isn't perfect, it represents a significant improvement in brevity and robustness over previous attempts.
Read more