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("finally sample"){
      7     printf("//! [finally sample]\n");
      8     auto values = rxcpp::observable<>::range(1, 3).
      9         finally([](){
     10             printf("The final action\n");
     11         });
     12     values.
     13         subscribe(
     14             [](int v){printf("OnNext: %d\n", v);},
     15             [](){printf("OnCompleted\n");});
     16     printf("//! [finally sample]\n");
     17 }
     18 
     19 SCENARIO("error finally sample"){
     20     printf("//! [error finally sample]\n");
     21     auto values = rxcpp::observable<>::range(1, 3).
     22         concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
     23         finally([](){
     24             printf("The final action\n");
     25         });
     26     values.
     27         subscribe(
     28             [](int v){printf("OnNext: %d\n", v);},
     29             [](rxcpp::util::error_ptr ep){
     30                 printf("OnError: %s\n", rxcpp::util::what(ep).c_str());
     31             },
     32             [](){printf("OnCompleted\n");});
     33     printf("//! [error finally sample]\n");
     34 }
     35