1 #include "../test.h" 2 3 SCENARIO("timer", "[!hide][periodically][timer][scheduler][long][perf][sources]"){ 4 GIVEN("the timer of 1 sec"){ 5 WHEN("the period is 1 sec"){ 6 using namespace std::chrono; 7 8 auto sc = rxsc::make_current_thread(); 9 auto so = rx::synchronize_in_one_worker(sc); 10 auto start = sc.now(); 11 auto period = seconds(1); 12 rx::composite_subscription cs; 13 rx::observable<>::timer(period, so) 14 .subscribe( 15 cs, __anonf78703bc0102(long counter)16 [=](long counter){ 17 auto nsDelta = duration_cast<milliseconds>(sc.now() - (start + (period * counter))); 18 std::cout << "timer : period " << counter << ", " << nsDelta.count() << "ms delta from target time" << std::endl; 19 }, __anonf78703bc0202(rxu::error_ptr)20 [](rxu::error_ptr){abort();}, __anonf78703bc0302()21 [](){std::cout << "completed" << std::endl;}); 22 } 23 } 24 } 25