Skip to content

Is it appropriate to mix Polly and FluentResults? #2159

Answered by peter-csala
dguisinger asked this question in Q&A
Discussion options

You must be logged in to vote

Here I have put together an example:

public class Program
{
	public static void Main()
	{
		var retry = new ResiliencePipelineBuilder<Result<int>>()
			.AddRetry(new ()
			{
				ShouldHandle = static args => args.Outcome switch
				{
						{ Result: { IsFailed: true, Errors: List<IError> errs } } when (errs.OfType<ExceptionalError>().Any()) => PredicateResult.True(),
						_ => PredicateResult.False()
				},
				MaxRetryAttempts = 5,
				OnRetry = static args =>
				{
					 Console.WriteLine("OnRetry, Attempt: {0}", args.AttemptNumber);
					return default;
				}
			})
			.Build();
		
		var res = retry.Execute(Get);
		res.Dump();
	}
	
	private static Result<int> Get()
	{
		return Result.Try<

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@dguisinger
Comment options

@peter-csala
Comment options

Answer selected by dguisinger
@dguisinger
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants