summaryrefslogtreecommitdiff
path: root/Rx/v2/examples
diff options
context:
space:
mode:
authorGrigoriy Chudnov <g.chudnov@gmail.com>2016-04-21 00:53:05 +0300
committerGrigoriy Chudnov <g.chudnov@gmail.com>2016-04-21 00:53:05 +0300
commit8fe51e452f711ca4fbb592502640a04c04a29278 (patch)
tree89105bd07f275f2096e3b034580d32cd559e8ea2 /Rx/v2/examples
parentc8bd50a50cc900889fa6bf6ae022c79ee5b5038e (diff)
downloadRxCpp-8fe51e452f711ca4fbb592502640a04c04a29278.tar.gz
add timestamp operator
Diffstat (limited to 'Rx/v2/examples')
-rw-r--r--Rx/v2/examples/doxygen/timestamp.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/Rx/v2/examples/doxygen/timestamp.cpp b/Rx/v2/examples/doxygen/timestamp.cpp
new file mode 100644
index 0000000..f17e5c0
--- /dev/null
+++ b/Rx/v2/examples/doxygen/timestamp.cpp
@@ -0,0 +1,51 @@
+#include "rxcpp/rx.hpp"
+
+#include "rxcpp/rx-test.hpp"
+#include "catch.hpp"
+
+SCENARIO("timestamp sample") {
+ printf("//! [timestamp sample]\n");
+
+ using namespace std::chrono;
+ auto values = rxcpp::observable<>::interval(milliseconds(100))
+ .timestamp()
+ .take(3);
+ values.
+ subscribe(
+ [](std::pair<long, typename rxsc::scheduler::clock_type::time_point> v) { printf("OnNext: %ld %lld\n", v.first, static_cast<long long>(v.second.time_since_epoch().count())); },
+ [](std::exception_ptr ep) {
+ try {
+ std::rethrow_exception(ep);
+ } catch (const std::exception& ex) {
+ printf("OnError: %s\n", ex.what());
+ }
+ },
+ []() { printf("OnCompleted\n"); });
+ printf("//! [timestamp sample]\n");
+}
+
+SCENARIO("timestamp operator syntax sample") {
+ using namespace rxcpp;
+ using namespace rxcpp::sources;
+ using namespace rxcpp::operators;
+ using namespace std::chrono;
+
+ typedef typename rxcpp::schedulers::scheduler::clock_type::time_point time_point;
+
+ printf("//! [timestamp operator syntax sample]\n");
+ auto values = interval(milliseconds(100))
+ | timestamp()
+ | take(3);
+ values.
+ subscribe(
+ [](std::pair<long, time_point> v) { printf("OnNext: %ld %lld\n", v.first, static_cast<long long>(v.second.time_since_epoch().count())); },
+ [](std::exception_ptr ep) {
+ try {
+ std::rethrow_exception(ep);
+ } catch (const std::exception& ex) {
+ printf("OnError: %s\n", ex.what());
+ }
+ },
+ []() { printf("OnCompleted\n"); });
+ printf("//! [timestamp operator syntax sample]\n");
+} \ No newline at end of file