Last active
March 31, 2019 01:33
-
-
Save maiconcp/79a0dbe47731db38ce3db1943884d6f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retry a specified number of times, using a function to | |
// calculate the duration to wait between retries based on | |
// the current retry attempt (allows for exponential backoff) | |
// In this case will wait for | |
// 2 ^ 1 = 2 seconds then | |
// 2 ^ 2 = 4 seconds then | |
// 2 ^ 3 = 8 seconds then | |
// 2 ^ 4 = 16 seconds then | |
// 2 ^ 5 = 32 seconds | |
Policy | |
.Handle<SomeException>() | |
.WaitAndRetry(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))) | |
.Execute(() => | |
{ | |
// myService.Post(...)... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment