Skip to content
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

how can I carry on a state (parameters, class instance) across the different tries #422

Closed
infofromca opened this issue Mar 25, 2018 · 5 comments
Labels

Comments

@infofromca
Copy link

infofromca commented Mar 25, 2018

At first , I think Context. but after search ,I found

/// <summary>
    /// Context that carries with a single execution through a Policy.   Commonly-used properties are directly on the class.  Backed by a dictionary of string key / object value pairs, to which user-defined values may be added.
    /// <remarks>Do not re-use an instance of <see cref="Context"/> across more than one execution.</remarks>
    /// </summary>

so, is it doable?
how can I achieve that?
thanks
andy

@reisenberger
Copy link
Member

Hi @infofromca Is your need to re-use a single Context instance/some parameter info across the multiple retries which a retry policy orchestrates for you? Or across multiple calls into a policy?

If you can provide a brief code sketch of what you are looking to achieve, we can probably help in more detail.

@infofromca
Copy link
Author

infofromca commented Mar 25, 2018

my use case is that I have a instance (S) to manipulate by retry system. after first (or second, or third..) retry , it has exception, now I need to get info(data) from exception, reassign this data to that instance(S). then try again.

as I understand , after each retry, instance (S) will be disposed. so I think to use Context, but Context is also disposed.
What should I do?
are there any place to keep the (modified) state across retries?
thanks
andy

@reisenberger
Copy link
Member

reisenberger commented Mar 25, 2018

Context is fully re-usable to keep the modified state across retries of a single call through .Execute() or .ExecuteAsync() on a retry policy.

(It is not intended for re-use across multiple calls through .Execute() or .ExecuteAsync().)

Re:

I need to get info(data) from exception

The onRetry/onRetryAsync policy hooks allow you to do this.

@infofromca
Copy link
Author

Thanks
I misunderstood between each .Execute() and each retry.
I will try it today

@reisenberger
Copy link
Member

@infofromca Thanks for raising this. I've clarified the intellisense, in #423 .

If you want more examples of the technique, we have a blog post on this. There's another nice example also in this recent discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants