question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce additional execute methods for ResilienceStrategy

See original GitHub issue

Introduce ExecuteValueTaskAsync methods for ValueTask-based callbacks (both void and T based):

  • (ResilienceContext, State)
  • (ResilienceContext)
  • (State, CancellationToken)
  • (CancellationToken)

Introduce ExecuteAsync methods for Task based callbacks (both void and T based):

  • (ResilienceContext, State)
  • (ResilienceContext)
  • (State, CancellationToken)
  • (CancellationToken)

Introduce Execute methods for synchronous callbacks (both void and T based):

  • (ResilienceContext, State)
  • (ResilienceContext)
  • (State, CancellationToken)
  • (CancellationToken)
  • (State)
  • ()

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
PeterCsalaHbocommented, Mar 23, 2023

Well, they are not exactly the same because you have made the context creation and context passing explicit. I think, it is an acceptable workaround. I’ve just wanted to highlight with the example that ExecuteAndCapture can be useful in implicit context passing.

IMHO keeping the API small and focused is a better design goal than supporting a case where a workaround is also acceptable. So, I’ve just wanted to get an answer whether the AndCapture overloads are left out intentionally or accidentally.

0reactions
martintmkcommented, Mar 22, 2023

@PeterCsalaHbo

Just for comparison the same thing done with V8:

public static class ContextExtensions
{
    private static readonly ResiliencePropertyKey<int> key = new("RetryCount");

    public static void IncreaseRetryCount(this ResilienceContext context)
    {
        context.Properties.Set(key, context.GetRetryCount() + 1);
    }

    public static int GetRetryCount(this ResilienceContext context)
    {
        if (context.Properties.TryGetValue(key, out int count))
        {
            return count;
        }

        return 0;
    }
}
var strategy = new ResilienceStrategyBuilder()
    .AddRetry(2, TimeSpan.FromSeconds(10), args => args.Context.IncreaseRetryCount())
    .Build();

var context = ResilienceContext.Get();
strategy.Execute(_ =>DoSomething(), context);
var retries = context.GetRetryCount();

Of course, we can add more convenience overloads based on the feedback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

23 Resilience Building Activities & Exercises for Adults
We blend resilience research with tactical activities and exercises to spark new ideas, foster empowerment, & help you build resilience.
Read more >
7 Strategies to Build a More Resilient Team
Commit to Building Each Other's Resilience: We call this “co-elevation.” It's essential to establish clear and unambiguous expectations around ...
Read more >
RESILIENCE STRATEGIES AND APPROACHES TO ...
This paper defines concepts related to systemic threats and reviews the analytical and governance approaches and strategies to manage these ...
Read more >
How To Be More Resilient: 8 Strategies for Difficult Times
Yale mental health experts discuss resilience and how to promote it, especially during difficult or stressful times.
Read more >
Resilience: Build skills to endure hardship
If you'd like to become more resilient, consider these tips: Get connected. ... Consider the skills and strategies that helped you through difficult...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found