I have several functions that rely on remote resource to return a result. This remote resource has a lot of errors or unexpected response that I can not change. There is a sequence of functions that each depends on the results of the function before. The logic of each function is different.
For example:
bool remoteFunction(string resource, string parameter = "")
{
// for example request
//for simplicity this is considered a request, but each function has different logic
return request.Url("example.com" + resource, parameter);
}
var firstResult = remoteFunction("a"); //1st step
var secondResult = remoteFunction("b", firstResult); //2nd step
var thirdResult = remoteFunction("c", secondResult); //3rd step
var fourthResult = remoteFunction("d", thirdResult); //4rth steo
What I want to do is:
- Keep retrying to do the function until it return the result we want. This can be done inside or outside the function.
- I want to be able to jump back from one function to a previous one and continue through the flow. i.e: jump from 4th step to 2nd step and continue from there.
What is the best design to do this ?
Thanks for the help
Clarification: To be more clear, I only want to go back in the sequence only if a function throws an exception. i.e: if 4rd function throws an exception, i have to go back to 1st and continue from there.
Aucun commentaire:
Enregistrer un commentaire