-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Add HandleResultAsync #329
Comments
Hi @larsbe . This is a great question! Makes total sense in terms of So: it would be possible to add
what should the policy do if a failure (disconnection/timeout) occurs during the
(But it's hard to reason still about where/how the eventual error gets expressed, if TL;DR: We liked the idea of As such, when faced with this kind of case, I've tended to take the two-stage calls of the original:
and just express a separate policy for each stage:
It's longer, but it's clear what each policy will handle/retry. To make it concise to client code, of course you can wrap it into a helper method. But: Does anyone have a better/alternative pattern to share? As you say, @larsbe, this is a common problem. |
A more minor issue is we don't at mo guarantee to call the We could easily refactor to remove that multiple execution, but at the minor expense of making every execution an execute-and-capture, and then discarding the 'capture' part again for the execute-only codepaths. |
Noting an additional angle for future ref: A If #281 goes through, For this reason, I'd recommend instead the approach in my original comment: keep all the async work in |
Thank you, @reisenberger, for the detailed answer! You argue for having a two-stage policy, however, this feels a bit like a workaround for me (at least in my case). Here is why: Your main argument is about the error handling and especially the unclear origin of exceptions, if you have a I do agree that a two-stage policy is the right way to go, if you have a complex operation inside a potential Regardless, thanks for the example you gave me. It definitely helps my case and I am going to implement it this way for now, but it just feels unnecessary complex for my needs. So, you might still want to consider my feedback! |
Closing as 'wont implement' for the reasons discussed earlier in this thread. At the moment in Polly, there is a clear distinction between lightweight Adding a |
For anyone exploring this problem, this Stackoverflow answer explores a possible solution to a similar case. |
With nested retry policies, wouldn't it retry |
Hey everybody,
today I ran into a case where handling a result involved executing an async operation:
So as you can see, I need to access the content of the response to decide whether to retry or not. Unfortunately the only way to parse it is with async methods. So to get it to work with
HandleResult
, I need to addResult
, which is not recommended and might lead to problems.The obvious solution would be to add a
HandleResultAsync
method to Polly, similar to e.g.Retry
andRetryAsync
. I haven't looked at the code myself yet, but maybe it's not too complicated to add the async counterpart and I think it would enable support for a quite frequent use case.Anyways, I love using Polly. It makes things a lot easier, so thanks for that! :)
The text was updated successfully, but these errors were encountered: