Last active
March 6, 2018 13:53
-
-
Save vector623/7f6d903ea73df4d227ec587412f83a4f to your computer and use it in GitHub Desktop.
retry web requests, with exponential backoff, using functional linq in c#
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
var labelsPage = Enumerable | |
.Range(0, 5) | |
.Select(pageAttempt => | |
{ | |
Thread.Sleep(2500 * pageAttempt * pageAttempt); | |
try | |
{ | |
var labelsAwql = "select LabelId,LabelName,LabelStatus limit 0,100"; | |
var attemptedlabelsPage = Config.LabelService.query(labelsAwql); | |
return attemptedlabelsPage; | |
} | |
catch (AdWordsApiException e) | |
{ | |
return null; | |
} | |
}) | |
.First(page => | |
{ | |
var nonNullFound = page != null; | |
return nonNullFound; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment