|
4
|
Encapsulates the logic of a retry loop using a generator function.
The retry loop is common in any code that deals with resources that might fail intermittently such as calls to remote servers. This generator function takes away the noise of retry loop implementation and encapsulates it into a structure that almost looks like a language feature and should be easy to understand for a reader even without looking at the implementation of the retryloop() generator. The fancy version adds delay and exponential backoff. It also preserves the original exception which terminated the retry loop, decorating it with useful information about the retry loop. Caveat: Calling retry() does not terminate the current attempt. You should use "retry() ; continue" if you have multiple try/catch statements in order to prevent it from trying the next step of an attempt even if one step has failed. |
Add a comment
Sign in to comment
Download
Copy to clipboard
