Coder Social home page Coder Social logo

Comments (1)

IEvangelist avatar IEvangelist commented on August 11, 2024

Hmmm, it actually does retry though. Let's talk it through quick... so here is the code:

public static async Task<T> WithRetry<T>(Func<Task<T>> action, int retryCount = 3)
{
    int retries = 0;
    while (true)
    {
        try
        {
            return await action().ConfigureAwait(false);                    
        }
        catch when (++ retries <= retryCount)
        {
            // Ease up a bit...
            await Delay(500).ConfigureAwait(false);
            return await TaskCache<T>.Default;
        }
    }
}

Scenario 1, if the given action is successful the first invocation to it... we're done, no reason to retry and we exit the while (true) loop.

Scenario 2, if the given action throws (imagine a transient error) on the first invocation, we're in a while loop... the catchwhen will enter as retries is only incremented to 1 and still less than the default retryCount of 3. We then await 500 milliseconds, oh! I see 👀 ... the return await TaskCache<T>.Default is actually wrong. That should be removed, that is a bug... nice catch.

from mirror.

Related Issues (8)

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.