aboutsummaryrefslogtreecommitdiffstats
path: root/Rx/v2/examples
diff options
context:
space:
mode:
authorKirk Shoop <kirk.shoop@microsoft.com>2015-07-09 19:44:27 -0700
committerKirk Shoop <kirk.shoop@microsoft.com>2015-07-09 21:19:43 -0700
commit9a16ae70998723a9e271ba6c8f3884fce0352202 (patch)
treec981f7f548a7d942b2f72b6a50b42003d6fc0be8 /Rx/v2/examples
parent52a0747aafb8a5edd523f79bae9edceb4f4f6cd0 (diff)
downloadplatform_external_Reactive-Extensions_RxCpp-9a16ae70998723a9e271ba6c8f3884fce0352202.tar.gz
platform_external_Reactive-Extensions_RxCpp-9a16ae70998723a9e271ba6c8f3884fce0352202.tar.bz2
platform_external_Reactive-Extensions_RxCpp-9a16ae70998723a9e271ba6c8f3884fce0352202.zip
added tap operator
Diffstat (limited to 'Rx/v2/examples')
-rw-r--r--Rx/v2/examples/doxygen/tap.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/Rx/v2/examples/doxygen/tap.cpp b/Rx/v2/examples/doxygen/tap.cpp
new file mode 100644
index 0000000..ad9d4e4
--- /dev/null
+++ b/Rx/v2/examples/doxygen/tap.cpp
@@ -0,0 +1,38 @@
+#include "rxcpp/rx.hpp"
+namespace rxu=rxcpp::util;
+
+#include "rxcpp/rx-test.hpp"
+#include "catch.hpp"
+
+SCENARIO("tap sample"){
+ printf("//! [tap sample]\n");
+ auto values = rxcpp::observable<>::range(1, 3).
+ tap(
+ [](int v){printf("Tap - OnNext: %d\n", v);},
+ [](){printf("Tap - OnCompleted\n");});
+ values.
+ subscribe(
+ [](int v){printf("Subscribe - OnNext: %d\n", v);},
+ [](){printf("Subscribe - OnCompleted\n");});
+ printf("//! [tap sample]\n");
+}
+
+SCENARIO("error tap sample"){
+ printf("//! [error tap sample]\n");
+ auto values = rxcpp::observable<>::range(1, 3).
+ concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
+ tap(
+ [](int v){printf("Tap - OnNext: %d\n", v);},
+ [](std::exception_ptr ep){
+ printf("Tap - OnError: %s\n", rxu::what(ep).c_str());
+ },
+ [](){printf("Tap - OnCompleted\n");});
+ values.
+ subscribe(
+ [](int v){printf("Subscribe - OnNext: %d\n", v);},
+ [](std::exception_ptr ep){
+ printf("Subscribe - OnError: %s\n", rxu::what(ep).c_str());
+ },
+ [](){printf("Subscribe - OnCompleted\n");});
+ printf("//! [error tap sample]\n");
+}