ulib/3party/rxcpp/Rx/v2/examples/doxygen/finally.cpp

35 lines
1.0 KiB
C++
Raw Normal View History

2024-01-10 09:33:36 +08:00
#include "rxcpp/rx.hpp"
#include "rxcpp/rx-test.hpp"
#include "catch.hpp"
SCENARIO("finally sample"){
printf("//! [finally sample]\n");
auto values = rxcpp::observable<>::range(1, 3).
finally([](){
printf("The final action\n");
});
values.
subscribe(
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
printf("//! [finally sample]\n");
}
SCENARIO("error finally sample"){
printf("//! [error finally sample]\n");
auto values = rxcpp::observable<>::range(1, 3).
concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
finally([](){
printf("The final action\n");
});
values.
subscribe(
[](int v){printf("OnNext: %d\n", v);},
[](rxcpp::util::error_ptr ep){
printf("OnError: %s\n", rxcpp::util::what(ep).c_str());
},
[](){printf("OnCompleted\n");});
printf("//! [error finally sample]\n");
}