so i have not really worked too much with C++ promise and future and i am unable to understand how i can add retries to a method that returns a promise but i have a method like below
promise<void> foo(Request){
/// There are N steps and i want to retry one of them <
/// if any one of the step fails the function can return
promise<void>::reject(std::errc::bar);
....
/// we are at the end, everything succeed
return promise::fulfilled();
}
But the issue is that one of the steps is flaky and i want to add retries for it, please note that i am not thinking of adding sleep and retry again because i do not want to block the thread.
so what i want is to move all the execution code in some new internal method like this
promise<void> executeFoo(Request request){
...
/// have all code here
...
}
and than
promise<void> foo(Request request){
/// have a utility class that can invoke methods on some delay
/// and a fixed number of time, so something like
return promise<void> {Util::Retry(/*delay_between_retries*/, /*number_Of_retries*/, /*some_other_thread*/, [&request](){
executeFoo(request);
})};
what is confusing me is that once promise foo(Request request) executes and promise is returned for the first time how can i fulfill/reject the promise later for consequent retries or should i cache the promise but thsi call can occur for other requests as well. I was not able to find any code online that showed how promise can work with retries, but if someone has some resources please do share. I understand that my code snippet are not actual code so any insights or pointers in this regard would be greatly appreciated.