Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created May 30, 2024 20:10
Show Gist options
  • Save dcomartin/203b73b0d64099d5196c07a278e077c0 to your computer and use it in GitHub Desktop.
Save dcomartin/203b73b0d64099d5196c07a278e077c0 to your computer and use it in GitHub Desktop.
using Polly;
var pipeline = new ResiliencePipelineBuilder<HttpResponseMessage>()
.AddConcurrencyLimiter(permitLimit: 10, queueLimit: 100)
.Build();
var httpClient = new HttpClient();
await Parallel.ForEachAsync(Enumerable.Range(0, 10).ToArray(), async (i, _) =>
{
var response = await pipeline.ExecuteAsync<HttpResponseMessage>(async _ => await httpClient.GetAsync("https://google.ca"));
Console.WriteLine($"Iteration: {i}, Response: {response.StatusCode}");
});
Console.WriteLine("Done");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment