Giter Site home page Giter Site logo

futurum-dev / dotnet.futurum.core.polly Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 65 KB

Small dotnet library, allowing you to use Polly with Futurum.Core, based on the concepts behind 'Railway Oriented Programming'.

Home Page: https://docs.futurum.dev/

License: MIT License

C# 100.00%
csharp dotnet functional-programming polly polly-resilience railway-oriented-programming result-type

dotnet.futurum.core.polly's Introduction

Futurum.Core.Polly

license CI Coverage Status NuGet version

Small dotnet library, allowing you to use Polly with Futurum.Core, based on the concepts behind 'Railway Oriented Programming'.

Try

Try to run func, using the Polly policy. If the policy fails, the failing result will be returned as a failure.

var result = await ResultPolly.TryAsync(func, () => ERROR_MESSAGE, pollyPolicy);

ThenTry

Combines Result.Then with ResultPolly.Try

var outputResult = await inputResult.ThenTryAsync(func, () => ERROR_MESSAGE, pollyPolicy);

HandleResult

Create a policy to handle Result

Policy.Handle<Exception>()
      .HandleResult()

HandleResult<T>

Create a policy to handle Result<T>

Policy.Handle<Exception>()
      .HandleResult<string>()

DelegateResult extensions

GetErrorMessage

Get the error message either from the Exception or the Result / Result<T>

var errorMessage = delegateResult.GetErrorMessage()
_pollyPolicy = Policy.Handle<Exception>()
                     .HandleResult<string>()
                     .WaitAndRetryAsync(new []{TimeSpan.FromSeconds(5), },
                                        (delegateResult, timeSpan, retryCount, context) =>
                                        {
                                            var error = delegateResult.GetErrorMessage();
                                            
                                            _logger.LogWarning("Retry - retryCount: '{RetryCount}'. Error : '{Error}'", retryCount, error);
                                        });

DelegateResult GetErrorMessageSafe

Get the safe error message either from the Exception or the Result / Result<T>

var errorMessage = delegateResult.GetErrorMessageSafe()
_pollyPolicy = Policy.Handle<Exception>()
                     .HandleResult<string>()
                     .WaitAndRetryAsync(new []{TimeSpan.FromSeconds(5), },
                                        (delegateResult, timeSpan, retryCount, context) =>
                                        {
                                            var error = delegateResult.GetErrorMessageSafe();
                                            
                                            _logger.LogWarning("Retry - retryCount: '{RetryCount}'. Error : '{Error}'", retryCount, error);
                                        });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.