1 #include "rxcpp/rx.hpp" 2 3 #include "rxcpp/rx-test.hpp" 4 #include "catch.hpp" 5 6 SCENARIO("timestamp sample") { 7 printf("//! [timestamp sample]\n"); 8 9 typedef rxcpp::schedulers::scheduler::clock_type::time_point time_point; 10 11 using namespace std::chrono; 12 auto values = rxcpp::observable<>::interval(milliseconds(100)) 13 .timestamp() 14 .take(3); 15 time_point start = rxcpp::identity_current_thread().now(); 16 values. 17 subscribe( __anon4e116de30102(std::pair<long, time_point> v) 18 [&](std::pair<long, time_point> v) { 19 long long int ms = duration_cast<milliseconds>(v.second - start).count(); 20 printf("OnNext: %ld @%lldms\n", v.first, ms); 21 }, __anon4e116de30202(std::exception_ptr ep) 22 [](std::exception_ptr ep) { 23 try { 24 std::rethrow_exception(ep); 25 } catch (const std::exception& ex) { 26 printf("OnError: %s\n", ex.what()); 27 } 28 }, __anon4e116de30302() 29 []() { printf("OnCompleted\n"); }); 30 printf("//! [timestamp sample]\n"); 31 } 32 33 SCENARIO("timestamp operator syntax sample") { 34 using namespace rxcpp; 35 using namespace rxcpp::sources; 36 using namespace rxcpp::operators; 37 using namespace std::chrono; 38 39 typedef rxcpp::schedulers::scheduler::clock_type::time_point time_point; 40 41 printf("//! [timestamp operator syntax sample]\n"); 42 auto values = interval(milliseconds(100)) 43 | timestamp() 44 | take(3); 45 time_point start = rxcpp::identity_current_thread().now(); 46 values. 47 subscribe( __anon4e116de30402(std::pair<long, time_point> v) 48 [&](std::pair<long, time_point> v) { 49 long long int ms = duration_cast<milliseconds>(v.second - start).count(); 50 printf("OnNext: %ld @%lldms\n", v.first, ms); 51 }, __anon4e116de30502(std::exception_ptr ep) 52 [](std::exception_ptr ep) { 53 try { 54 std::rethrow_exception(ep); 55 } catch (const std::exception& ex) { 56 printf("OnError: %s\n", ex.what()); 57 } 58 }, __anon4e116de30602() 59 []() { printf("OnCompleted\n"); }); 60 printf("//! [timestamp operator syntax sample]\n"); 61 }