summaryrefslogtreecommitdiff
path: root/Rx/v2/examples/doxygen/observe_on.cpp
blob: 927c339c93948c3b7478b2c6df31cf3af9cbc6ca (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 "rxcpp/rx.hpp"

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

std::string get_pid();

SCENARIO("observe_on sample"){
    printf("//! [observe_on sample]\n");
    printf("[thread %s] Start task\n", get_pid().c_str());
    auto values = rxcpp::observable<>::range(1, 3).
        map([](int v){
            printf("[thread %s] Emit value %d\n", get_pid().c_str(), v);
            return v;
        });
    values.
        observe_on(rxcpp::synchronize_new_thread()).
        as_blocking().
        subscribe(
            [](int v){printf("[thread %s] OnNext: %d\n", get_pid().c_str(), v);},
            [](){printf("[thread %s] OnCompleted\n", get_pid().c_str());});
    printf("[thread %s] Finish task\n", get_pid().c_str());
    printf("//! [observe_on sample]\n");
}