Skip to content

Instantly share code, notes, and snippets.

@vector623
Last active March 6, 2018 13:53
Show Gist options
  • Save vector623/7f6d903ea73df4d227ec587412f83a4f to your computer and use it in GitHub Desktop.
Save vector623/7f6d903ea73df4d227ec587412f83a4f to your computer and use it in GitHub Desktop.
retry web requests, with exponential backoff, using functional linq in c#
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