summaryrefslogtreecommitdiff
path: root/Rx/v2/test/sources/timer.cpp
blob: 3f46b213bd828c9b4c37fb893050d88e4acbcc15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "../test.h"

SCENARIO("timer", "[!hide][periodically][timer][scheduler][long][perf][sources]"){
    GIVEN("the timer of 1 sec"){
        WHEN("the period is 1 sec"){
            using namespace std::chrono;

            auto sc = rxsc::make_current_thread();
            auto so = rx::synchronize_in_one_worker(sc);
            auto start = sc.now();
            auto period = seconds(1);
            rx::composite_subscription cs;
            rx::observable<>::timer(period, so)
                .subscribe(
                    cs,
                    [=](long counter){
                        auto nsDelta = duration_cast<milliseconds>(sc.now() - (start + (period * counter)));
                        std::cout << "timer          : period " << counter << ", " << nsDelta.count() << "ms delta from target time" << std::endl;
                    },
                    [](rxu::error_ptr){abort();},
                    [](){std::cout << "completed" << std::endl;});
        }
    }
}