summaryrefslogtreecommitdiff
path: root/Rx/v2/examples/doxygen/from.cpp
blob: 7cc22768e3dedaf380a35bee5914ec4c86fe72df (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
#include "rxcpp/rx.hpp"

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

SCENARIO("from sample"){
    printf("//! [from sample]\n");
    auto values = rxcpp::observable<>::from(1, 2, 3);
    values.
        subscribe(
            [](int v){printf("OnNext: %d\n", v);},
            [](){printf("OnCompleted\n");});
    printf("//! [from sample]\n");
}

#include "main.hpp"

SCENARIO("threaded from sample"){
    printf("//! [threaded from sample]\n");
    printf("[thread %s] Start task\n", get_pid().c_str());
    auto values = rxcpp::observable<>::from(rxcpp::observe_on_new_thread(), 1, 2, 3).map([](int v){
        printf("[thread %s] Emit value: %d\n", get_pid().c_str(), v);
        return v;
    });
    values.
        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("//! [threaded from sample]\n");
}