I'm trying to make an observable that when an error is detected, this will be execute again, but did notice something , when "on_error()" with "retry" operator is execute, this only re-run again the Observable but, the current instance of Observable still in the current stack, in other words is still alive
I did make a test to verify the behavior
#include <string>
#include "rxcpp/rx.hpp"
class test_class
{
public:
int a;
test_class() {
printf("Create Obj \n");
a = 1;
}
~test_class() {
printf("Destroy Obj \n");
a = 0;
}
};
int main()
{
// Create Observable request
auto values = rxcpp::observable<>::create<std::string>(
[&](rxcpp::subscriber<std::string> subscriber) {
test_class test;
while (subscriber.is_subscribed()) {
std::exception_ptr eptr = std::current_exception();
subscriber.on_error(eptr);
int a;
a = 2;
subscriber.on_next("normal");
}
})
.retry()
.as_dynamic();
values.
subscribe(
[](std::string v) {
printf("OnNext: %s\n", v.c_str()); },
[](std::exception_ptr ep) {
printf("OnError: %s\n", rxcpp::util::what(ep).c_str()); },
[]() {
printf("OnCompleted\n"); });
}
So, my input output is
Create Obj
Create Obj
Create Obj
Create Obj
...
I did expect to see "Destroy Obj" output as well
also I got a Stack overflow exception
My goal is , execute an Observable Object, that when an error is triggered, this could be restart again, but destroying curruent one, in orden to prevent Stack overflow exception
Maybe there's exist another way to make this, could you help me?