summaryrefslogtreecommitdiff
path: root/Rx/v2/examples/doxygen/timer.cpp
blob: 635b283dcd459596611d58fa693734777f3f6d3d (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "rxcpp/rx.hpp"

#include "rxcpp/rx-test.hpp"
#include "catch.hpp"

SCENARIO("timepoint timer sample"){
    printf("//! [timepoint timer sample]\n");
    auto start = std::chrono::steady_clock::now() + std::chrono::milliseconds(1);
    auto values = rxcpp::observable<>::timer(start);
    values.
        subscribe(
            [](int v){printf("OnNext: %d\n", v);},
            [](){printf("OnCompleted\n");});
    printf("//! [timepoint timer sample]\n");
}

SCENARIO("duration timer sample"){
    printf("//! [duration timer sample]\n");
    auto period = std::chrono::milliseconds(1);
    auto values = rxcpp::observable<>::timer(period);
    values.
        subscribe(
            [](int v){printf("OnNext: %d\n", v);},
            [](){printf("OnCompleted\n");});
    printf("//! [duration timer sample]\n");
}

SCENARIO("threaded timepoint timer sample"){
    printf("//! [threaded timepoint timer sample]\n");
    auto scheduler = rxcpp::observe_on_new_thread();
    auto start = scheduler.now() + std::chrono::milliseconds(1);
    auto values = rxcpp::observable<>::timer(start, scheduler);
    values.
        as_blocking().
        subscribe(
            [](int v){printf("OnNext: %d\n", v);},
            [](){printf("OnCompleted\n");});
    printf("//! [threaded timepoint timer sample]\n");
}

SCENARIO("threaded duration timer sample"){
    printf("//! [threaded duration timer sample]\n");
    auto scheduler = rxcpp::observe_on_new_thread();
    auto period = std::chrono::milliseconds(1);
    auto values = rxcpp::observable<>::timer(period, scheduler);
    values.
        as_blocking().
        subscribe(
            [](int v){printf("OnNext: %d\n", v);},
            [](){printf("OnCompleted\n");});
    printf("//! [threaded duration timer sample]\n");
}