| 8 | **/ |
| 9 | |
| 10 | int main() |
| 11 | { |
| 12 | //! [retry_when delay] |
| 13 | size_t retry_count = 0; |
| 14 | rpp::source::create<std::string>([&retry_count](const auto& sub) { |
| 15 | if (++retry_count != 4) |
| 16 | { |
| 17 | sub.on_error({}); |
| 18 | } |
| 19 | else |
| 20 | { |
| 21 | sub.on_next(std::string{"success"}); |
| 22 | sub.on_completed(); |
| 23 | } |
| 24 | }) |
| 25 | | rpp::operators::retry_when([](const std::exception_ptr&) { |
| 26 | return rpp::source::timer(std::chrono::seconds{5}, rpp::schedulers::current_thread{}); |
| 27 | }) |
| 28 | | rpp::operators::subscribe([](const std::string& v) { std::cout << v << std::endl; }); |
| 29 | // Source observable is resubscribed after 5 seconds on each error emission |
| 30 | //! [retry_when delay] |
| 31 | |
| 32 | //! [retry_when] |
| 33 | retry_count = 0; |
| 34 | rpp::source::create<std::string>([&retry_count](const auto& sub) { |
| 35 | if (++retry_count != 4) |
| 36 | { |
| 37 | sub.on_error({}); |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | sub.on_next(std::string{"success"}); |
| 42 | sub.on_completed(); |
| 43 | } |
| 44 | }) |
| 45 | | rpp::operators::retry_when([](const std::exception_ptr& ep) { |
| 46 | try |
| 47 | { |
| 48 | std::rethrow_exception(ep); |
| 49 | } |
| 50 | catch (const std::runtime_error&) |
| 51 | { |
| 52 | return rpp::source::timer(std::chrono::seconds{5}, rpp::schedulers::current_thread{}); |
| 53 | } |
| 54 | catch (...) |
| 55 | { |
| 56 | throw; |
| 57 | } |
| 58 | }) |
| 59 | | rpp::operators::subscribe([](const std::string& v) { std::cout << v << std::endl; }); |
| 60 | // Source observable is resubscribed after 5 seconds only on particular error emissions |
| 61 | //! [retry_when] |
| 62 | return 0; |
| 63 | } |
nothing calls this directly
no test coverage detected