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