1 #include "rxcpp/rx.hpp" 2 namespace rxu=rxcpp::util; 3 4 #include "rxcpp/rx-test.hpp" 5 #include "catch.hpp" 6 7 SCENARIO("tap sample"){ 8 printf("//! [tap sample]\n"); 9 auto values = rxcpp::observable<>::range(1, 3). 10 tap( 11 [](int v){printf("Tap - OnNext: %d\n", v);}, 12 [](){printf("Tap - OnCompleted\n");}); 13 values. 14 subscribe( 15 [](int v){printf("Subscribe - OnNext: %d\n", v);}, 16 [](){printf("Subscribe - OnCompleted\n");}); 17 printf("//! [tap sample]\n"); 18 } 19 20 SCENARIO("error tap sample"){ 21 printf("//! [error tap sample]\n"); 22 auto values = rxcpp::observable<>::range(1, 3). 23 concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))). 24 tap( 25 [](int v){printf("Tap - OnNext: %d\n", v);}, 26 [](std::exception_ptr ep){ 27 printf("Tap - OnError: %s\n", rxu::what(ep).c_str()); 28 }, 29 [](){printf("Tap - OnCompleted\n");}); 30 values. 31 subscribe( 32 [](int v){printf("Subscribe - OnNext: %d\n", v);}, 33 [](std::exception_ptr ep){ 34 printf("Subscribe - OnError: %s\n", rxu::what(ep).c_str()); 35 }, 36 [](){printf("Subscribe - OnCompleted\n");}); 37 printf("//! [error tap sample]\n"); 38 } 39