Home | History | Annotate | Download | only in doxygen
      1 #include "rxcpp/rx.hpp"
      2 
      3 #include "rxcpp/rx-test.hpp"
      4 #include "catch.hpp"
      5 
      6 SCENARIO("repeat sample"){
      7     printf("//! [repeat sample]\n");
      8     auto values = rxcpp::observable<>::from(1, 2).
      9         repeat().
     10         take(5);
     11     values.
     12         subscribe(
     13             [](int v){printf("OnNext: %d\n", v);},
     14             [](){printf("OnCompleted\n");});
     15     printf("//! [repeat sample]\n");
     16 }
     17 
     18 SCENARIO("repeat count sample"){
     19     printf("//! [repeat count sample]\n");
     20     auto values = rxcpp::observable<>::from(1, 2).repeat(3);
     21     values.
     22         subscribe(
     23             [](int v){printf("OnNext: %d\n", v);},
     24             [](){printf("OnCompleted\n");});
     25     printf("//! [repeat count sample]\n");
     26 }
     27 
     28 SCENARIO("repeat error sample"){
     29     printf("//! [repeat error sample]\n");
     30     auto values = rxcpp::observable<>::from(1, 2).
     31         concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
     32         repeat();
     33     values.
     34         subscribe(
     35             [](int v){printf("OnNext: %d\n", v);},
     36             [](std::exception_ptr ep){
     37                 try {std::rethrow_exception(ep);}
     38                 catch (const std::exception& ex) {
     39                     printf("OnError: %s\n", ex.what());
     40                 }
     41             },
     42             [](){printf("OnCompleted\n");});
     43     printf("//! [repeat error sample]\n");
     44 }
     45