1 #include "rxcpp/rx.hpp"
2 
3 #include "rxcpp/rx-test.hpp"
4 #include "catch.hpp"
5 
6 SCENARIO("retry sample"){
7     printf("//! [retry sample]\n");
8     auto values = rxcpp::observable<>::from(1, 2).
9         concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
10         retry().
11         take(5);
12     values.
13         subscribe(
__anona525bd3e0102(int v)14             [](int v){printf("OnNext: %d\n", v);},
__anona525bd3e0202()15             [](){printf("OnCompleted\n");});
16     printf("//! [retry sample]\n");
17 }
18 
19 SCENARIO("retry count sample"){
20     printf("//! [retry count sample]\n");
21     auto source = rxcpp::observable<>::from(1, 2).
22         concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source")));
23     auto values = source.retry(3);
24     values.
25         subscribe(
__anona525bd3e0302(int v)26             [](int v){printf("OnNext: %d\n", v);},
__anona525bd3e0402(std::exception_ptr ep)27             [](std::exception_ptr ep){
28                 try {std::rethrow_exception(ep);}
29                 catch (const std::exception& ex) {
30                     printf("OnError: %s\n", ex.what());
31                 }
32             },
__anona525bd3e0502()33             [](){printf("OnCompleted\n");});
34     printf("//! [retry count sample]\n");
35 }
36 
37 //SCENARIO("retry hot sample"){
38 //    printf("//! [retry hot sample]\n");
39 //    auto values = rxcpp::observable<>::timer(std::chrono::milliseconds(10)).
40 //        concat(rxcpp::observable<>::error<long>(std::runtime_error("Error1 from source"))).
41 //        concat(rxcpp::observable<>::timer(std::chrono::milliseconds(10))).
42 //        concat(rxcpp::observable<>::error<long>(std::runtime_error("Error2 from source"))).
43 //        concat(rxcpp::observable<>::timer(std::chrono::milliseconds(10))).
44 //        concat(rxcpp::observable<>::error<long>(std::runtime_error("Error3 from source"))).
45 //        concat(rxcpp::observable<>::timer(std::chrono::milliseconds(10))).
46 //        concat(rxcpp::observable<>::error<long>(std::runtime_error("Error4 from source"))).
47 //        retry(3);
48 //    values.
49 //        subscribe(
50 //            [](long v){printf("OnNext: %d\n", v);},
51 //            [](std::exception_ptr ep){
52 //                try {std::rethrow_exception(ep);}
53 //                catch (const std::exception& ex) {
54 //                    printf("OnError: %s\n", ex.what());
55 //                }
56 //            },
57 //            [](){printf("OnCompleted\n");});
58 //    printf("//! [retry hot sample]\n");
59 //}
60 //
61 //SCENARIO("retry completed sample"){
62 //    printf("//! [retry completed sample <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<]\n");
63 //    auto source = rxcpp::observable<>::from(1, 2).
64 //        concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
65 //        publish();
66 //    auto values = source.retry();
67 //    //auto values = rxcpp::observable<>::timer(std::chrono::milliseconds(10)).
68 //    //    concat(rxcpp::observable<>::error<long>(std::runtime_error("Error1 from source"))).
69 //    //    concat(rxcpp::observable<>::timer(std::chrono::milliseconds(10))).
70 //    //    concat(rxcpp::observable<>::error<long>(std::runtime_error("Error2 from source"))).
71 //    //    concat(rxcpp::observable<>::timer(std::chrono::milliseconds(10))).
72 //    //    retry(3);
73 //    values.
74 //        subscribe(
75 //            [](long v){printf("OnNext: %d\n", v);},
76 //            [](std::exception_ptr ep){
77 //                try {std::rethrow_exception(ep);}
78 //                catch (const std::exception& ex) {
79 //                    printf("OnError: %s\n", ex.what());
80 //                }
81 //            },
82 //            [](){printf("OnCompleted\n");});
83 //    printf("//! [retry completed sample]\n");
84 //}
85