Skip to content

Instantly share code, notes, and snippets.

View reisenberger's full-sized avatar

Dylan Reisenberger reisenberger

View GitHub Profile
@reisenberger
reisenberger / DecorrelatedJitter.cs
Last active September 25, 2019 20:15
Demonstrates decorrelated jitter with Polly (issue 245)
using System;
using System.Collections.Generic;
using Polly;
namespace DecorrelatedJitter
{
class Program
{
static void Main(string[] args)
{
@reisenberger
reisenberger / extracted_from_PolicyAsync.cs
Last active January 14, 2016 21:10
Add attempt count to Policy.ExecuteAndCaptureAsync(...), ref Polly #73
public async Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<CancellationToken, Task<TResult>> action, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
if (_asyncExceptionPolicy == null) throw new InvalidOperationException(
"Please use the asynchronous RetryAsync, RetryForeverAsync, WaitAndRetryAsync or CircuitBreakerAsync methods when calling the asynchronous Execute method.");
try
{
var result = default(TResult);
int attempts = 0; // Added
await _asyncExceptionPolicy(async ct =>
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Polly;
namespace PollyThreadSleepVersusTaskDelay
{
class Program